Openweathermap with input from a GPS

I am trying to use weather data from Openweathermap and have tried both the Openweathermap node and the Http Request node but run into problems with both.

With the Openweathermap node I have two issues. Firstly, I believe it should be able to accept a Lat and Lng in the form of 53.1234567 and -1.1234567 (msg.location.lat and msg.location.lon).


But I have been unable to achieve this and receive an "incorrect format" notification message. After many internet searches I have not been able to find any mention or examples of passing lat and lng to the node in the form of msg.location.lat or GPS.

The second issue I have, I get this with the Openweathermap node (manually entering lat and lng) and the Http Request node. The returned message is cut short, ending in three dots.


I see this in a debug node, to prove I saved the returned message to a flow context, see image.

If I put the same URL into a web browser I get the full message returned. Why is it shortened in Node-Red and how do I get around this?

My problems are most likely my poor programming skills, any pointers would be appreciated.

Thanks

This works for me:

So does this:
Untitled 3

The three dots are probably just the returned message being truncated by the debug node. Try sending it to a file to check.

That also works for me too but I want to feed live locations in which, if I've read correctly, should be in the form msg.location.lat.

I did try sending the returned information to a flow context but that is also shortened. If the flow context shortens it too that seems wrong to me.

This works for me too

Are you setting msg.location.lon or msg.location.lng?

If you share your HTTP request URL (with the API key censored) I will see exactly what it returns for me.

Interesting that Latitude and Longitude only remain visible when "combined current weather/forecast for" is selected! The GPS signal comes from a Victron product and requires two node, Lat and Lon, in my example I've used two inject nodes and requires a Join node I think.

Putting a debug after the Join and the Weather node shows me the output but gives errors.

Thanks

[{"id":"9b84eee8fcc75cce","type":"tab","label":"Test","disabled":false,"info":"","env":[]},{"id":"1e98914fb0c2fe4f","type":"openweathermap","z":"9b84eee8fcc75cce","name":"","wtype":"onecall","lon":"","lat":"","city":"","country":"","language":"en","credentials":{},"x":570,"y":220,"wires":[["f16beaf7e3922283"]]},{"id":"3544db347dfee80e","type":"change","z":"9b84eee8fcc75cce","name":"","rules":[{"t":"set","p":"location.lat","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"lat","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":220,"wires":[["d042ef24a8138520"]]},{"id":"1decc165472dfebe","type":"inject","z":"9b84eee8fcc75cce","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"53.34","payloadType":"num","x":130,"y":220,"wires":[["3544db347dfee80e"]]},{"id":"f16beaf7e3922283","type":"debug","z":"9b84eee8fcc75cce","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":610,"y":280,"wires":[]},{"id":"c35696bab8288a5e","type":"change","z":"9b84eee8fcc75cce","name":"","rules":[{"t":"set","p":"location.lon","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"lon","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":280,"wires":[["d042ef24a8138520"]]},{"id":"ea3a66925e5eec2f","type":"inject","z":"9b84eee8fcc75cce","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"-1.0","payloadType":"num","x":110,"y":280,"wires":[["c35696bab8288a5e"]]},{"id":"d042ef24a8138520","type":"join","z":"9b84eee8fcc75cce","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":450,"y":260,"wires":[["1e98914fb0c2fe4f"]]}]

Umm.

Well using two inputs and a join creates msg.payload {"lat":53.34,"lon":-1} and you are after msg.location {"lat":53.34,"lon":-1}

If your GPS gives lat and long as seperate messages, a Change node after the Join can move the values into msg.location

I appreciate your help as it gives me the chance to discuss my earlier finds. Here is the debug from the attached code.

Screenshot 2022-01-31 13.33.49

Also here is the debug from the Victron GPS nodes. Why the Lon from the GPS gives an array I don't understand. I previously moved the lon position out of the array, sorry I can't remember the result.

type or paste code here


[{"id":"9b84eee8fcc75cce","type":"tab","label":"Test","disabled":false,"info":"","env":},{"id":"1e98914fb0c2fe4f","type":"openweathermap","z":"9b84eee8fcc75cce","name":"","wtype":"onecall","lon":"","lat":"","city":"","country":"","language":"en","x":610,"y":120,"wires":[["049322490bcde89d"]]},{"id":"1decc165472dfebe","type":"inject","z":"9b84eee8fcc75cce","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"53.34","payloadType":"num","x":90,"y":240,"wires":[["ccf0bd414262e12b"]]},{"id":"ea3a66925e5eec2f","type":"inject","z":"9b84eee8fcc75cce","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"-1.0","payloadType":"num","x":90,"y":280,"wires":[["d3eccd93b125b1de"]]},{"id":"d042ef24a8138520","type":"join","z":"9b84eee8fcc75cce","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":370,"y":260,"wires":[["8c40b4117404774e","1e98914fb0c2fe4f"]]},{"id":"ccf0bd414262e12b","type":"change","z":"9b84eee8fcc75cce","name":"","rules":[{"t":"set","p":"location.lat","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"lat","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":200,"wires":[["d042ef24a8138520"]]},{"id":"d3eccd93b125b1de","type":"change","z":"9b84eee8fcc75cce","name":"","rules":[{"t":"set","p":"location.lon","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"lon","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":320,"wires":[["d042ef24a8138520"]]},{"id":"8c40b4117404774e","type":"debug","z":"9b84eee8fcc75cce","name":"msg2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":570,"y":260,"wires":},{"id":"049322490bcde89d","type":"debug","z":"9b84eee8fcc75cce","name":"msg1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":630,"y":180,"wires":}]

Firstly, to share code:
a) copy the code in Node-red
b) click the </> button
c) paste your code over the highlighted "type or paste code here"
The code you pasted cannot be imported because the forum has stripped out some characters.
A screengrab showing your flow can be helpful, as long as you also paste the code.

Secondly, pictures of payloads are of no value. Please copy the value from the debug pane (there is a "copy value" button) and paste here as with code.

So far I have not seen any proof that you are setting msg.location to an object containing lat and long.

Sorry about code in the last message, too many interruptions to concentrate.

[{"id":"9b84eee8fcc75cce","type":"tab","label":"Test","disabled":false,"info":"","env":[]},{"id":"1e98914fb0c2fe4f","type":"openweathermap","z":"9b84eee8fcc75cce","name":"","wtype":"onecall","lon":"","lat":"","city":"","country":"","language":"en","x":690,"y":80,"wires":[["049322490bcde89d"]]},{"id":"1decc165472dfebe","type":"inject","z":"9b84eee8fcc75cce","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"53.34","payloadType":"num","x":90,"y":240,"wires":[["ccf0bd414262e12b"]]},{"id":"ea3a66925e5eec2f","type":"inject","z":"9b84eee8fcc75cce","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"-1.0","payloadType":"num","x":90,"y":280,"wires":[["d3eccd93b125b1de"]]},{"id":"d042ef24a8138520","type":"join","z":"9b84eee8fcc75cce","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":550,"y":260,"wires":[["1e98914fb0c2fe4f","010d3dcb35bd7b14"]]},{"id":"ccf0bd414262e12b","type":"change","z":"9b84eee8fcc75cce","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"lat","tot":"str"},{"t":"set","p":"location.lat","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":200,"wires":[["917873fba721156b","d042ef24a8138520"]]},{"id":"d3eccd93b125b1de","type":"change","z":"9b84eee8fcc75cce","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"lon","tot":"str"},{"t":"set","p":"location.lon","pt":"msg","to":"payload","tot":"msg","dc":true}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":320,"wires":[["6fbbe44f9ac7f8c8","d042ef24a8138520"]]},{"id":"049322490bcde89d","type":"debug","z":"9b84eee8fcc75cce","name":"msg1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":710,"y":140,"wires":[]},{"id":"917873fba721156b","type":"debug","z":"9b84eee8fcc75cce","name":"Rule1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":480,"y":120,"wires":[]},{"id":"6fbbe44f9ac7f8c8","type":"debug","z":"9b84eee8fcc75cce","name":"Rule2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":450,"y":380,"wires":[]},{"id":"010d3dcb35bd7b14","type":"debug","z":"9b84eee8fcc75cce","name":"join","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":710,"y":260,"wires":[]}]

From debug Rule1

{"_msgid":"e5abb02080e69906","payload":53.34,"topic":"lat","location":{"lat":53.34}}```

From debug Rule2

{"_msgid":"5235999e423e26bc","payload":-1,"topic":"lon","location":{"lon":-1}}

From debug join

{"_msgid":"9d71ecbad43cbc5e","payload":{"lat":53.34,"lon":-1},"topic":"lat","location":{"lat":53.34}}

And from the openweathermap node I get

Invalid location information provided


I hope this is of more use

Your join debug shows you have
msg.payload = {lat: 53.34, lon: -1}
msg.location = {lon: -1} OR {lat:53.34}
(Because the join node only joins messages into msg.payload)

As I said earlier, use a change node after the join to make msg.location = msg.payload.
You don't gain anything by setting msg.location.whatever in your initial change nodes.

Thank you for your help @jbudd , i think in the last few days I have been very close but your help and explanations have been invaluable. I can now proceed, phew.

Should anyone else struggle like I have, here is my code.

[{"id":"9b84eee8fcc75cce","type":"tab","label":"Test","disabled":false,"info":"","env":[]},{"id":"1e98914fb0c2fe4f","type":"openweathermap","z":"9b84eee8fcc75cce","name":"","wtype":"onecall","lon":"","lat":"","city":"","country":"","language":"en","x":690,"y":300,"wires":[["049322490bcde89d"]]},{"id":"1decc165472dfebe","type":"inject","z":"9b84eee8fcc75cce","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"53.34","payloadType":"num","x":90,"y":240,"wires":[["ccf0bd414262e12b"]]},{"id":"ea3a66925e5eec2f","type":"inject","z":"9b84eee8fcc75cce","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"-1.0","payloadType":"num","x":90,"y":280,"wires":[["d3eccd93b125b1de"]]},{"id":"d042ef24a8138520","type":"join","z":"9b84eee8fcc75cce","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":270,"y":260,"wires":[["b0c77a81da6c4804"]]},{"id":"ccf0bd414262e12b","type":"change","z":"9b84eee8fcc75cce","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"lat","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":250,"y":200,"wires":[["917873fba721156b","d042ef24a8138520"]]},{"id":"d3eccd93b125b1de","type":"change","z":"9b84eee8fcc75cce","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"lon","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":250,"y":320,"wires":[["6fbbe44f9ac7f8c8","d042ef24a8138520"]]},{"id":"049322490bcde89d","type":"debug","z":"9b84eee8fcc75cce","name":"msg1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":710,"y":380,"wires":[]},{"id":"917873fba721156b","type":"debug","z":"9b84eee8fcc75cce","name":"Rule1","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":450,"y":200,"wires":[]},{"id":"6fbbe44f9ac7f8c8","type":"debug","z":"9b84eee8fcc75cce","name":"Rule2","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":490,"y":320,"wires":[]},{"id":"45c116eb61a3f927","type":"change","z":"9b84eee8fcc75cce","name":"","rules":[{"t":"set","p":"location","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":220,"wires":[["6002f506e41afa1a","1e98914fb0c2fe4f"]]},{"id":"6002f506e41afa1a","type":"debug","z":"9b84eee8fcc75cce","name":"Rule3","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":700,"y":540,"wires":[]},{"id":"6928302ff43cc1ae","type":"victron-input-gps","z":"9b84eee8fcc75cce","service":"com.victronenergy.gps.ve_ttyACM0","path":"/Position/Latitude","serviceObj":{"service":"com.victronenergy.gps.ve_ttyACM0","name":"NMEA-0183 GPS (ACM0)","paths":[{"path":"/Altitude","type":"float","name":"Altitude (m)"},{"path":"/Course","type":"float","name":"Course (Deg)"},{"path":"/Fix","type":"integer","name":"Fix"},{"path":"/NrOfSatellites","type":"integer","name":"Number of satellites"},{"path":"/Position/Latitude","type":"float","name":"Latitude (LAT)"},{"path":"/Position/Longitude","type":"float","name":"Longitude (LNG)"},{"path":"/Speed","type":"float","name":"Speed (m/s)"}]},"pathObj":{"path":"/Position/Latitude","type":"float","name":"Latitude (LAT)"},"name":"","x":200,"y":140,"wires":[["ccf0bd414262e12b"]]},{"id":"0794e95e771bf9fa","type":"victron-input-gps","z":"9b84eee8fcc75cce","service":"com.victronenergy.gps.ve_ttyACM0","path":"/Position/Longitude","serviceObj":{"service":"com.victronenergy.gps.ve_ttyACM0","name":"NMEA-0183 GPS (ACM0)","paths":[{"path":"/Altitude","type":"float","name":"Altitude (m)"},{"path":"/Course","type":"float","name":"Course (Deg)"},{"path":"/Fix","type":"integer","name":"Fix"},{"path":"/NrOfSatellites","type":"integer","name":"Number of satellites"},{"path":"/Position/Latitude","type":"float","name":"Latitude (LAT)"},{"path":"/Position/Longitude","type":"float","name":"Longitude (LNG)"},{"path":"/Speed","type":"float","name":"Speed (m/s)"}]},"pathObj":{"path":"/Position/Longitude","type":"float","name":"Longitude (LNG)"},"name":"","x":210,"y":380,"wires":[["d3eccd93b125b1de"]]},{"id":"b0c77a81da6c4804","type":"delay","z":"9b84eee8fcc75cce","name":"","pauseType":"rate","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"10","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"allowrate":false,"outputs":1,"x":460,"y":260,"wires":[["45c116eb61a3f927"]]}]

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.