Node-red TCP Node convert Buffer to string

3,781 views
Skip to first unread message

Tijl Dullers

unread,
Sep 19, 2016, 2:18:36 PM9/19/16
to Node-RED
Hi,

I have a very basic question, however I can't seem to find the answer.
I have a program that writes data to node-red using the TCP IN node.

The data only comes in correctly when I configure the TCP in node as a stream of buffer payloads.
This way, when enabling my debug node I get each 'line' of input as a buffer[7].
The readable content of this buffer is exactly the way I need it, but to further  process the data ( e.g. do deduplication' etc)  I need to be able to convert the buffer to a string without changing its content ( without decoding to UTF-8 or whatever).

Example of the payload here below,

msg.payload : buffer [7]04f92e8a053484

Can someone bring some enlightment on how to do this ?

Thanks


Tijl Dullers

unread,
Sep 19, 2016, 3:54:58 PM9/19/16
to Node-RED
After some trial and error, it seems to be as simple as using a function node containing:

msg.payload = msg.payload.toString('hex');
return msg;

This then returns

msg.payload : string [14]04f92e8a053484

Which is identical to my buffer but now in a usable format

msg.payload : buffer [7]04f92e8a053484



Op maandag 19 september 2016 20:18:36 UTC+2 schreef Tijl Dullers:
Reply all
Reply to author
Forward
0 new messages