Search code examples
javascriptnode.jsnode-red

create binary payload in node-red


New to node-red and javascript. I need to use the TCP input to connect to a relay controller for status. I'm using a function node to generate a two-byte request that will flow to the TCP input node and on to the controller but don't know how to format this in java. I can set

msg.payload = "hello";

to send a string, but I need to send 2 bytes: 0xEF 0xAA. In C# I would just create the string

msg.payload = "\xEF\xAA";

or something. How to do this in java/node-red?


Solution

  • Binary payloads are NodeJS buffer objects so can be created like this:

    msg.payload = new Buffer([0xEF,0xAA]);