I'm receiving data from a Dragino temp sensor via a UDP node. The payload contains 25 bytes that i need to convert to string.
According to Dragino, i have a frame definition i need to follow to i guess separate the bytes and convert them somehow to string.
How do i start?
The output i get from UDP is a Buffer.
I do not have any experience at all working with buffers and bytes
Here is the frame definition.
I guess i would need to use the node-red-contrib-binary , but after reading the quick ref, I'm not sure i will have any success with it...
Something like this could be a starting point, in a function node.
(if I understand the document correctly)
let Cursor = 0;
let Buf = buffer.slice(Cursor,Cursor+length)
Cursor = Cursor + length
let DeviceID = Read(msg.payload,6)
let Version = Read(msg.payload,2)
let Battery = Read(msg.payload,2)
let SignalStrength = Read(msg.payload,1)
let MOD = Read(msg.payload,1)
let TEMP0 = Read(msg.payload,2)
let DigitalIn = Read(msg.payload,1)
let ADC = Read(msg.payload,2)
let TEMP1 = Read(msg.payload,2)
let Humid = Read(msg.payload,2)
let Timestamp = Read(msg.payload,4)
Disclaimer: I have not checked this, and you may need to parse the sliced byte groups to an integer.
It seems to work.
Doing Timestamp.readInt32BE() yields 1634122045 => 2021-10-13T10:47:25.000Z