Creation of Function Node

Writing code for decoder function node for decoding hexadecimal payload of lorawan gps tracker.LW001-BG.pdf (231.6 KB)

I don't see a question?

This wil explain u better

Could you decode the buffer array and extract out latitude and longitude coordinates as json objects?

Not really, I still don't see a question.

flows (1).json (3.7 KB)
Here is the flows file for ur refrence.

What you need to do is to tell us what the input you are receiving looks like, how the data is encoded and what you want to get out.
Also note that a JSON object is always a string, perhaps you mean you want to get javascript objects out, or perhaps just values.

Yes Colin I have parsed the data in 1st function node using simple JSON.parse and extracted out the data attribute from JSON object{} method then passed it into base64 function inorder to change into buffer array of hexadecimal values.Now I require decoding of the same array (as done in ttn) with help of another function node to get result as json objects having values of latitude and longitude.

I want something just like shown in image of thingsnetwork

flows (1).json (3.7 KB)

But i need some code also for decoding only parser node will not give result in debug window.please check my flow1 and gps pdf file for better understanding of flow.LW001-BG.pdf (231.6 KB)

Ok, so you have a Buffer containing the data 0x61, 0x67 etc and you want to extract the data from that and put it into a javascript object (not a JSON object, JSON is always a string).
I believe that to do that you would be best using node-red-contrib-buffer-parser rather than a function node. Your problem is exactly what the node is designed for.

For the future, if you want to post a flow (which I don't think is necessary in this case) then use the </> at the top of the forum text field and paste the flow in.

This contains more information about the sensor lw001-bg gps sensor

Acording to the PDF with sample data you could so this...

which matches this...

using buffer parser set as per the info you provided...

Demo flow...

[{"id":"99b86a91.cc8f18","type":"inject","z":"b489a0e4.4dd7e","name":"test data AgH5e5xFaIdRRA==","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"data\":\"AgH5e5xFaIdRRA==\"}","payloadType":"json","x":820,"y":100,"wires":[["88fc873f.c086c8"]]},{"id":"2bb51028.cbdab","type":"buffer-parser","z":"b489a0e4.4dd7e","name":"","data":"","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatle","name":"lat","offset":2,"length":1,"offsetbit":0,"scale":1,"mask":""},{"type":"floatle","name":"lon","offset":6,"length":1,"offsetbit":0,"scale":1,"mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"output","multipleResult":false,"setTopic":true,"x":1110,"y":160,"wires":[["2057e639.f3a49a"]]},{"id":"b4228108.10405","type":"debug","z":"b489a0e4.4dd7e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1290,"y":100,"wires":[]},{"id":"2057e639.f3a49a","type":"debug","z":"b489a0e4.4dd7e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1290,"y":160,"wires":[]},{"id":"363f26cc.7e8fda","type":"inject","z":"b489a0e4.4dd7e","name":"click me","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":760,"y":160,"wires":[["2b6a66d1.86484a"]]},{"id":"2b6a66d1.86484a","type":"function","z":"b489a0e4.4dd7e","name":"test data 02 01 F9 7B 9C 45 68 87 51 44","func":"msg.payload = { data: Buffer.from(\"0201F97B9C4568875144\", \"hex\") }\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":860,"y":200,"wires":[["2bb51028.cbdab","29572a95.8942b6"]]},{"id":"88fc873f.c086c8","type":"base64","z":"b489a0e4.4dd7e","name":"","action":"","property":"","x":1100,"y":100,"wires":[["b4228108.10405","2bb51028.cbdab"]]},{"id":"29572a95.8942b6","type":"debug","z":"b489a0e4.4dd7e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1290,"y":200,"wires":[]}]

Thanks Steve this works perfect. :blush: :heart_eyes:

Thanks collin i learnt json is a string not an object. :blush:

hello do u know steve which node can help me plot or track latitude and longitude on a map?
I tried node red world map but in that u have to manually give coordinates.

Pretty sure you can pass a message with coordinates into the world map node. Start a new thread for a new problem (with an appropriate title so it attracts the right people)

Just look at the info side bar for the world map for the simplest example.

In information tab its wriiten that it requires 3 fields name,lat and long for world map node.

how can i add this data field also?and also would like to show a red color marker on location.

Hmmm I wonder which node could be used to “change” properties on a message ?

1 Like

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