Function nodes must always return a Javascript object -- your code pulls the payload value (a buffer of 1 character) out of the incoming msg
object, converts it to a string, and tries to return a bare string. This is not allowed, since the downstream nodes always expect to receive a msg object.
The best practice would be to reuse the incoming msg object, but replace the payload field:
// replace the payload buffer with the string value
msg.payload = msg.payload.toString('utf8');
// return the original msg with the new string payload
return msg;
This practice ensures that any other properties (or fields) of the incoming msg (e.g. topic, parts, msgid, req, res, etc) are not destroyed -- which can cause things like the join
and http response
nodes to not work.
Also, simulating buffer input in an inject
node is pretty simple, since there is a buffer option. If you click the ...
next to the input field, it opens a buffer editor panel which shows the hex values of each character as you type:
Your case is a bit different, since you know the hex value -- in this case, you can type each hex string into the field directly, as long as you use brackets to denote an array, double quotes around each hex "string", and separate each hex string with a comma, like so:
Whew! -- ugly, but it works...
NR Team: are there any plans to enhance the Buffer input field to accept valid syntax for JS arrays? Right now if I type "hello" in the buffer editor, then the field value is set to [104,101,108,108,111]
(the ascii equivalent). But the alternate hex (or octal, or binary) forms like [0x68,0x65,0x6C,0x6C,0x6F]
are treated as a plain string.