Webhookrelay data extract for WorldMap?

Hello everyone, I've been working on some node red projects and have been having a very difficult time working with a Webhookrelay. The data that is transmitted from my remote device is HTTP_POST format, but when it arrives into Nodered using the Webhookrelay service, all relevant data shows in the "body". I need to be able to submit the data into the WorldMap node in the proper format. I have tried parsing, change nodes, function nodes, but my programming skills are very basic and getting the right function is proving difficult. Can someone please help me with getting just the basic data for WorldMap extracted from this clock of text.

WorldMap minimum data: msg.payload = { "name":"Jason", "lat":51.05, "lon":-1.35 }

Screenshot 2021-01-24 130100
Screenshot 2021-01-24 130709

here is an example of how to parse the body into a object, using a change node

[{"id":"94186213.9747e8","type":"inject","z":"57675e72.26a0d8","name":"","props":[{"p":"body","v":"test=23&test2=another&test3=234.56","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":120,"y":2820,"wires":[["b8412457.7243f"]]},{"id":"b8412457.7243f","type":"change","z":"57675e72.26a0d8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$split(body,\"&\").${$substringBefore($, \"=\"):$substringAfter($, \"=\")}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":2800,"wires":[["662e84ea.e38f1c"]]},{"id":"662e84ea.e38f1c","type":"debug","z":"57675e72.26a0d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":2700,"wires":[]}]

When creating a Change Node, how should I configure it? (Set/Change?) I've seen some of your responses on other topics and I'm trying to figure out what you mean on these strings. I'm familiar with Arduino programming and electronics manipulation, but still trying to grasp this language.

I think once I have a working example it will be much easier to start modifying for the sake of understanding and manipulating what the various {}, , etc mean.

The string i posted is a flow.json, which is a json string.

you need to copy the flow, then press crtl i, in the node-red editor. Then paste the copied flow, and then press import button. The flow will then appear in the editor.
https://nodered.org/docs/user-guide/editor/workspace/import-export

1 Like

THAT WORKED! Thank you, I just learned quite a bit from breaking down your flow. Next I need to change the titles, for example "latitude" to "lat". I then ended up using another Change Node to Move the payload to the proper label format. It was then that I realized my GPS location is only approximate and that there is must be a way to decode the data in the transmission, which will give me precise gps, speed, etc. But that's an all new obstacle. Thanks E1cid

If its coming from a real GPS then it may be in nmea format or d.m.s not d.d

Also you can move the payload properties in the same change node. as long as they are lower in the list, i.e. after the original jsonata expression .

[{"id":"6ee7e31e.295814","type":"function","z":"57675e72.26a0d8","name":"Text transformation","func":"var msg = { payload: \"Thing : \" + msg.payload + \" - I think thats a thing\"};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":270,"y":2940,"wires":[["495a2fce.f5b8c8","6530c869.bcffd"]]},{"id":"495a2fce.f5b8c8","type":"debug","z":"57675e72.26a0d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":3000,"wires":[]},{"id":"6530c869.bcffd","type":"change","z":"57675e72.26a0d8","name":"Transform into payload.test from payload","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.test","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":2940,"wires":[["209c2a6b.651876","b3611dc2.ace18"]]},{"id":"909fa323.0cfa1","type":"inject","z":"57675e72.26a0d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":270,"y":3000,"wires":[["6ee7e31e.295814"]]},{"id":"209c2a6b.651876","type":"debug","z":"57675e72.26a0d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.test","targetType":"msg","statusVal":"","statusType":"auto","x":1110,"y":2940,"wires":[]},{"id":"b3611dc2.ace18","type":"debug","z":"57675e72.26a0d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1090,"y":2980,"wires":[]}]

Well, I was going to try to tackle the next part alone. But while I have your expertise, maybe you can help clarify this as well.

I had an issue after your solution above where I realized that the payload.data field was HEX encoded. I decoded it with

msg.payload.data = Buffer.from(msg.payload.data, 'hex').toString();
return msg;

That gave me a decoded text of:

51.000000,-110.000000,21.30,0.0,0

I need to then convert that string into:
lat: XX.XXXXXX
lon: XX.XXXXXX
altitude: XX.XX
speed: X.X
course: X

Any tips on formatting this and appending this to the previous solution?

Its not NMEA data because in the code on another platform I only wanted that data from the NMEA that was coming in, to reduce total data being transmitted. After this project I am definitely taking some courses on this language!

The simplest way would be to split the string on the "," then assign the array values .

msg.payload.data= msg.payload.data.split(",");
msg.payload.data = {"lat": msg.payload.data[0],
                    "lon": msg.payload.data[1],
                    "altitude": msg.payload.data[2],
                    "speed": msg.payload.data[3],
                    "couse": msg.payload.data[4]};

if you use track instead of course then the worldmap node will display a leader line indicating that direction proportional to the speed :wink:

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