Interpreting payload message from LORA Gateway

Hi,
I have some trouble in interpreting the message payload received from the LORA gateway.
The payload is received correctly and it contains sensor data from three sensors.
The payload received is as follows,
"payload": [ 1, 68, 4, 155, 39, 2, 66, 24, 183, 80, 3, 65, 208, 248, 232 ],

1, 2 and 3 in the payload are the identifiers of the particular sensor data. Each identifier is followed by 4 bytes of data. Now I am trying to interpret the decimal data to float. I have tried with a javascript but I am not successful. It gives me the wrong data. The code I have used is

//byte location in the incoming data packets
var data_type = {
none : 0X00,
CO2 : 0x01,
Humid : 0x02,
Temp : 0x03,
};

var data_struc = {
CO2 : 0,
Humid :0,
Temp : 0,
};

pData = data_struc;
var msg_pntr = 0;

while (msg_pntr < msg.payload.length){
switch (msg_pntr){
case data_type.none:
msg_pntr++;
break;
case data_type.CO2:
pData.CO2 =
parseFloat(msg.payload.toString('hex', 1, 4));
msg_pntr++;
break;
case data_type.Humid:
pData.Humid =
parseFloat(msg.payload.toString('hex', 6, 9));
msg_pntr++;
break;
case data_type.Temp:
pData.Temp =
parseFloat(msg.payload.toString('hex', 11, 14));
msg_pntr++;
break;
default:
msg_pntr++;
}
}
msg.pData = pData;
return {payload:msg};

Could some please help me on this.

Thanks in advance.

One of the great things about Node-RED is the richness of contrib nodes.

For your use case there is the node-red-contrib-binary that can parse the array of value to create an object. It will work fine if the structure of the data is fixed (like seems to be the case). I provide a testing flow below, assuming that Lora uses little-endian serialization.

b-02

Testing flow:

[{"id":"1db46797.7d5118","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"e02a7c95.d1aba","type":"inject","z":"1db46797.7d5118","name":"Array ","topic":"","payload":"[1,68,4,155,39,2,66,24,183,80,3,65,208,248,232]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":100,"wires":[["e8532cf2.8641"]]},{"id":"a4cefeb2.fc678","type":"binary","z":"1db46797.7d5118","name":"","pattern":"b8=> sensor1, l32f => value1, b8=> sensor2, l32f => value2, b8=> sensor3, l32f => value3","x":450,"y":100,"wires":[["35aad0e3.67366"]]},{"id":"35aad0e3.67366","type":"debug","z":"1db46797.7d5118","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":630,"y":100,"wires":[]},{"id":"e8532cf2.8641","type":"function","z":"1db46797.7d5118","name":"create test buffer","func":"msg.payload = new Buffer(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":100,"wires":[["a4cefeb2.fc678"]]}]

When you install the contrib-node it will add an example in the library:

Hi Andrei,

Thanks for your kind response. I am trying to install (node-red-contrib-binary) node but my Node-RED web interface is failing to install. I tried to restart the browser and also the computer still failing to install. I am using node Node-RED interface through Multitech Connect web application. Attached few images.

Thanks again.
Partheepan

The error message you got suggest that you don´t have connectivity from your network to NPM. Are you using a corporate network behind firewalls our proxies ?

Anyways I suggest that you ask the question on Multitech forum. It is better to have guidance from a product specialist as you may want to verify if the software in your device (firmware, node.js version, etc) support the installation of contrib-nodes.

It would be nice that you return to this post afterward to update us on the outcome. We may learn from your experience.

http://www.multitech.net/developer/forums/topic-tag/node-red/

Thank you. I have posted in their forum. Will update you on the reply.

1 Like

not sure multitech will add much - it is as @Andrei said not connected to the internet so can't reach npm.

Hi @Andrei and @dceejay I don't think so Multitech is going to help on it as it is hard for me to connect the conduit to the internet. Is there any alternative way other than using internet?

thanks.

You can decode using a function node and Node.JS Buffer methods. No need to install aditional contrib nodes (despite that they help a lot in many use cases).

Again, I am assuming the stream of data has always the same form (3 readings of four bytes).

Edit: You may want to merge the two function nodes in only one (I forgot to do so before posting)

r-02

[{"id":"2cd9235f.0776cc","type":"function","z":"95df0638.a188a8","name":"buffer payload","func":"msg.payload = new Buffer(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":260,"y":480,"wires":[["d32addc8.2cc8d"]]},{"id":"e069545d.ba9b38","type":"inject","z":"95df0638.a188a8","name":"Array ","topic":"","payload":"[1,68,4,155,39,2,66,24,183,80,3,65,208,248,232]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":480,"wires":[["2cd9235f.0776cc"]]},{"id":"840151d2.ea499","type":"debug","z":"95df0638.a188a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":630,"y":440,"wires":[]},{"id":"d32addc8.2cc8d","type":"function","z":"95df0638.a188a8","name":"Read Buffer","func":"let buf = msg.payload;\nlet m1 = {\"payload\" : buf.readFloatBE(1)};\nlet m2 = {\"payload\" : buf.readFloatBE(6)};\nlet m3 = {\"payload\" : buf.readFloatBE(11)};\nreturn [[m1,m2,m3]];","outputs":3,"noerr":0,"x":450,"y":480,"wires":[["840151d2.ea499"],["380ebb30.465ce4"],["b7d070a4.6c759"]]},{"id":"380ebb30.465ce4","type":"debug","z":"95df0638.a188a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":630,"y":480,"wires":[]},{"id":"b7d070a4.6c759","type":"debug","z":"95df0638.a188a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":630,"y":520,"wires":[]}]

How do I get Lora node in nodered?

This thread is four years old so I’m going to close it.

If you have an issue after searching for a Lora node (look at the Flows tab) then please open a new thread and explain your issue and remember no one but you knows your setup and what you have tried. :wink: