Format Buffer to HexString in function node

Hi all,
I need to do a rather simple task. I would like to format this Buffer:

var char = Buffer.from([0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xef])

in a function node (or any other way) as a HexString:

var str = "7e000000000000ffef"

To be able to send this hex stream via gatttool to bluetooth client.
Unfortunately I got completely stuck. Could you please help me ?

Hello .. you can try .. .toString("hex")

var char = Buffer.from([0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xef])

msg.payload = char.toString("hex")

return msg;

Result:

image

.. alternatively you can use the node-red-contrib-buffer-parser node
with these settings

that should give you the same result

Hello !

It works. Nice and easy ! Thanks a lot.

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