Extract a part of string from a payload

Form my LoRa Module I receive the ascii buffer:
msg.payload = Buffer.from("240E5048556D366420A262000026200F00AA7400", "hex")
In this buffer I have a DevEUI from the module : E5048556D366420
I would like to save this DevEUI in the variable (ID = E5048556D366420)
How can I process? (without to use the node “buffer parser”)
Thank for the future answer…

You can use toString("hex") to convert the buffer to a string like the one you started with, and then use substring() to extract the part you want.

Thank you for your answer...
I used the routine bellow:

var Buf = Buffer.from(mes, "hex");
var val = Buffer.from([Buf[1], Buf[2], Buf[3], Buf[4], Buf[5], Buf[6], Buf[7],Buf[8]]);
var ID = val.toString('hex');

And works.


I think you can optimise this somewhat.

var Buf = Buffer.from(mes, "hex").slice(1,8);
var ID = Buf.toString('hex');

Thank you, it works well...
I am a beginner in Node-RED (Node.js) and I don't know all the "subtleties"!

1 Like

Plenty of us here!
Researching the answers given, gaining an understanding on the solutions schematic will go a long way!

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