Decoding a Lora Data

Hi

I was wondering if anyone could help me.

I have data coming in from lora gateway and the data is msg.payload : string[6]
"4031e7"

Now I know the format of the data is this.(provide from manufactures datasheet.)

Use the 1st 2nd and 5th points to calculate the temperature
Use the 3rd 4th and 6th points to calculate the Relative humidity

So

40e if I do a hex to decimal I get 1038. Then subtract 800 then divide by 10 and the answer is 23.8 DegC.
317 if I do a hex to decimal I get 791. Then subtract 250 then divide by 10 and the answer is 54.1 %RH

The above formula is provided by the manufacture

So I know that I am getting the right information from the sensor but I usually get the javascript from the manufacture unfortunately they do not provide it for this sensor.

I was hoping someone could point me in the write direction on how to write this in a function module so I get 2 objects out one called temp and one called humidity.

Thanks

Some pointers to get you going...

Use something like var temp = msg.payload.slice(0,2) + msg.payload.slice(4,1) to get 1 part. And a variation of that for other part.

Then use parseInt to convert hex string to integer.

So do a search on "js string slice" and "js parseInt"

You should be able to guess the rest.

2 Likes

Thanks Steve. Once I had the points split it was just a bit of maths.