Reading the udp data with a frame header

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 :roll_eyes:
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...

Here is the buffer array I have:


Might need some context here.



or is the definition you provided an example?
Should it be an actual string, or is the definition a series of integers?

The first array is the buffer from udp node...

Here are some instructions i have for the sensor.

Ok - this is handy.
Give me a few minutes.


Something like this could be a starting point, in a function node.
(if I understand the document correctly)

let Cursor = 0;
function Read(buffer,length){
    let Buf =  buffer.slice(Cursor,Cursor+length)
    Cursor = Cursor + length
    return Buf;

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

Will check it out when i get off work. Thanks for the quick responses sir :blush:

There is a node designed precisely for this kind of operation... node-red-contrib-buffer-parser

Search the forum for example uses. Read the "readme" and the built in help. Try out the built in demos (CTRL+I)


So I tested this, and the buffer array is now sorted throughout the properties, any help to actually get the string values ?

They are not strings - they are integers (I think), quite a different approach.
if using the node suggested by @Steve-Mcl - it should be built in?

if doing it manually however.

Properties with a length of 2;

Properties with a length of 4;

Properties with a length of 1;
as is: 0x08 = 8.

i.e Timestamp.readInt32BE()

I am not too hot on bits and bytes, a little maybe, but @Steve-Mcl may be more qualified

1 Like


Version.readInt61BE() returns 120

Which makes perfect sense!

But again, node-red-contrib-buffer-parser can do this for you

This data turns into this...


Using buffer parser (note: I had to guess some of the data types)

Demo flow...

1 Like

Thanks, guys for helping me.
Working with node-red for quite some time now, and there are still things to learn...

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