# Callback function arduino

**URL:** <https://discourse.nodered.org/t/callback-function-arduino/27021>\
**Category:** General\
**Created:** [21 May 2020 08:08 UTC](https://discourse.nodered.org/t/callback-function-arduino/27021 "2020-05-21T08:08:50Z")\
**Posts on this page:** 10\
**Page:** 2

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [21 May 2020 10:14 UTC](https://discourse.nodered.org/t/callback-function-arduino/27021/22 "2020-05-21T10:14:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![qmf](https://avatars.discourse-cdn.com/v4/letter/q/b487fb/32.png) [@qmf](https://discourse.nodered.org/u/qmf)\
**Post date:** [21 May 2020 10:15 UTC](https://discourse.nodered.org/t/callback-function-arduino/27021/23 "2020-05-21T10:15:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [21 May 2020 10:35 UTC](https://discourse.nodered.org/t/callback-function-arduino/27021/24 "2020-05-21T10:35:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![qmf](https://avatars.discourse-cdn.com/v4/letter/q/b487fb/32.png) [@qmf](https://discourse.nodered.org/u/qmf)\
**Post date:** [21 May 2020 10:38 UTC](https://discourse.nodered.org/t/callback-function-arduino/27021/25 "2020-05-21T10:38:30Z")

</div>

And why cannot I get the first byte? 😩

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [21 May 2020 10:47 UTC](https://discourse.nodered.org/t/callback-function-arduino/27021/26 "2020-05-21T10:47:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![qmf](https://avatars.discourse-cdn.com/v4/letter/q/b487fb/32.png) [@qmf](https://discourse.nodered.org/u/qmf)\
**Post date:** [21 May 2020 10:56 UTC](https://discourse.nodered.org/t/callback-function-arduino/27021/27 "2020-05-21T10:56:24Z")

</div>

Through the function node!

> [@ristomatti](#):
>
> The hexadecimal representation for 'h' in your Node-RED debug console was not correct in the earlier screenshot you sent.

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

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [21 May 2020 10:59 UTC](https://discourse.nodered.org/t/callback-function-arduino/27021/28 "2020-05-21T10:59:48Z")

</div>

> [@qmf](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [21 May 2020 11:04 UTC](https://discourse.nodered.org/t/callback-function-arduino/27021/29 "2020-05-21T11:04:46Z")

</div>

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:

```auto
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`.

---

<div class="post-metadata">

**Author:** ![qmf](https://avatars.discourse-cdn.com/v4/letter/q/b487fb/32.png) [@qmf](https://discourse.nodered.org/u/qmf)\
**Post date:** [21 May 2020 12:05 UTC](https://discourse.nodered.org/t/callback-function-arduino/27021/30 "2020-05-21T12:05:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [4 June 2020 12:05 UTC](https://discourse.nodered.org/t/callback-function-arduino/27021/31 "2020-06-04T12:05:07Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/callback-function-arduino/27021.md?page=1)
