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.