Callback function arduino

You are already sending it as ASCII data.

It displays as characters in the Arduino serial terminal because you are casting the values to char type.

True, and that's what I said, I want it exactly as I have, but not missing the first character

mqtt itself has no concept of strings or buffers - it just sends the bytes you give it. if you send it "hello" it will deliver the bytes 0x68, 0x65, 0x6c, 0x6c, 0x6f

And why cannot I get the first byte? :weary:

Are you still sending it through the function node or like @knolleary suggested? The hexadecimal representation for 'h' in your Node-RED debug console was not correct in the earlier screenshot you sent.

Through the function node!

I know! That's what I'm trying to fix!

I thought you wanted to send the output from the form node to the MQTT node and on to your arduino.

Because replacing the Function node with the Change node does exactly that.

Is there a reason you want to stick with your Function node and not use the Change node?

As @dceejay says, MQTT has no knowledge of Strings - it just sends binary data. If you pass the node the string "hello", it will publish the binary data 0x68, 0x65, 0x6c, 0x6c, 0x6f - which is identical to if you passed the node a Buffer object containing those same bytes.

If you are just interested to know why your Function node ends up with a 0x0 as the first byte, that is because of this line:

buf.writeUInt8(rs485);

I don't know what you think that line is doing, but at that point in the Function buf is already a Buffer object containing the bytes from msg.payload.rs485text. That line then overwrites the first byte with a 0.

OMG! That is the solution! Thank you so much!

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