# Passing MQTT Message issues

**URL:** <https://discourse.nodered.org/t/passing-mqtt-message-issues/14612>\
**Category:** General\
**Created:** [21 August 2019 14:22 UTC](https://discourse.nodered.org/t/passing-mqtt-message-issues/14612 "2019-08-21T14:22:36Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Exit2Studios](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/exit2studios/32/10998_2.png) [@Exit2Studios](https://discourse.nodered.org/u/Exit2Studios)\
**Post date:** [21 August 2019 14:22 UTC](https://discourse.nodered.org/t/passing-mqtt-message-issues/14612/1 "2019-08-21T14:22:36Z")

</div>

I am trying to pass some sensor values from an arduino to MQTT within home assistant. The MQTT Broker is picking up the message, but no payload is attached. Here are a few screenshots, and willing to share more if it helps troubleshoot, but I'm relatively new to mqtt, so not sure what I'm missing.

 ![40%20AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/84ed5d6cd514e936933360ec643abbc66e382d1f.png)  
 ![02%20AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/b00860b005d9b0fda7c0f5dd8f0e619340e0f12d.png)

As you can see, there is a temperature value being passed (the NR dashboard gauge reflects it accurately), but according to mqtt.fx there are no values coming through.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [21 August 2019 15:35 UTC](https://discourse.nodered.org/t/passing-mqtt-message-issues/14612/2 "2019-08-21T15:35:51Z")

</div>

Maybe it's me, but I see `payload` in your screenshots ?  
I am not familiair with mqtt.fx, should it show the message ? (for a more visualized method, try [mqttexplorer](http://mqtt-explorer.com))

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [21 August 2019 18:02 UTC](https://discourse.nodered.org/t/passing-mqtt-message-issues/14612/3 "2019-08-21T18:02:24Z")

</div>

I'm not sure I'm following either. The debug in your screen shot is labelled "MQTT debug"  
but none of the messages in the debug panel come from that debug.

The easiest way to check that you are sending what you think you should be sending would be to add a debug to share the inputs to your MQTT-OUT node.

And then subscribe to the same topic with a MQTT-IN node and attach a debug to that. Give both debug nodes sensible names and you should easily see what you are sending.

---

<div class="post-metadata">

**Author:** ![Exit2Studios](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/exit2studios/32/10998_2.png) [@Exit2Studios](https://discourse.nodered.org/u/Exit2Studios)\
**Post date:** [21 August 2019 18:18 UTC](https://discourse.nodered.org/t/passing-mqtt-message-issues/14612/4 "2019-08-21T18:18:08Z")

</div>

It appears to be working via the debugs, but I'm not getting anything in HA

 ![19%20PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/d53659ba6ac159701ab6881dfc1bab3ea1af70a6.png)

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [21 August 2019 18:50 UTC](https://discourse.nodered.org/t/passing-mqtt-message-issues/14612/5 "2019-08-21T18:50:24Z")

</div>

So it’s either a problem with HA or HA can’t cope with the format of the payload.

There’s a return character at the end of the string. You could try deleting the character so you send just a number and see if that works

---

<div class="post-metadata">

**Author:** ![Exit2Studios](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/exit2studios/32/10998_2.png) [@Exit2Studios](https://discourse.nodered.org/u/Exit2Studios)\
**Post date:** [21 August 2019 18:51 UTC](https://discourse.nodered.org/t/passing-mqtt-message-issues/14612/6 "2019-08-21T18:51:36Z")

</div>

I was wondering about that extra character as well...not sure how to delete it or even why it's there. The value is passing according to mqqt explorer:

 ![37%20PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/da914c85b5fef2502ff01208cd91ed69885742df.png)

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [21 August 2019 19:06 UTC](https://discourse.nodered.org/t/passing-mqtt-message-issues/14612/7 "2019-08-21T19:06:33Z")

</div>

Use a function node

[https://duckduckgo.com/?q=javascript+strip+last+character](https://duckduckgo.com/?q=javascript+strip+last+character)

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [21 August 2019 19:45 UTC](https://discourse.nodered.org/t/passing-mqtt-message-issues/14612/8 "2019-08-21T19:45:40Z")

</div>

The return character is whitespace at the end. Do you know where it is coming from? For example with the default serial node it can often be handled by editing the config node you can set what character to split messages on. This specific return character is the Carriage Return Line Feed, represented in a visual string like that arrow, and in text as `\r\n`.

Have you tried editing the input to split on `\r\n` rather than the default `\n`?  
 ![30](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/f162ffd4e04fd4eed1920b3405ba9cd7628733db.png)  
This would solve the problem from the start. In general, you can use `msg.payload = msg.payload.trim()` in a function node to strip of whitespace from the start and end of a string. As for stripping the last character, there are other methods, but as you appear to deal with whitespace specific issues here, use the road of least resistance 🙂

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [21 August 2019 22:18 UTC](https://discourse.nodered.org/t/passing-mqtt-message-issues/14612/9 "2019-08-21T22:18:06Z")

</div>

I have been down a very similar road to yours.

I receive MQTT messages and wanted to parse their content.

I got bogged down with the formatting of the message. The solution for me was to put the message through a `JSON` node first.

---

<div class="post-metadata">

**Author:** ![Exit2Studios](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/exit2studios/32/10998_2.png) [@Exit2Studios](https://discourse.nodered.org/u/Exit2Studios)\
**Post date:** [21 August 2019 23:29 UTC](https://discourse.nodered.org/t/passing-mqtt-message-issues/14612/10 "2019-08-21T23:29:04Z")

</div>

I tried editing the input and it just moved the carriage return to before the payload and got the following error?

`TypeError [ERR_INVALID_ARG_TYPE]: The "list[1]" argument must be one of type Array, Buffer, or Uint8Array. Received type string`

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [22 August 2019 04:17 UTC](https://discourse.nodered.org/t/passing-mqtt-message-issues/14612/11 "2019-08-22T04:17:01Z")

</div>

Sure you get, show better WHAT you have edited and how it looks now, otherwise we cannot follow what you have done. An error message like that is not helping us to help you

---

<div class="post-metadata">

**Author:** ![Exit2Studios](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/exit2studios/32/10998_2.png) [@Exit2Studios](https://discourse.nodered.org/u/Exit2Studios)\
**Post date:** [22 August 2019 14:54 UTC](https://discourse.nodered.org/t/passing-mqtt-message-issues/14612/12 "2019-08-22T14:54:50Z")

</div>

I used the `msg.payload = msg.payload.trim()` as listed above and now it has just the number without any additional characters. I'm still not getting a result in Home Assistant, so I'm thinking I may need something in the template value to get it readable, so I should probably take that question to the HA forum lol unless anyone here has any suggestions.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 August 2019 20:58 UTC](https://discourse.nodered.org/t/passing-mqtt-message-issues/14612/13 "2019-08-22T20:58:19Z")

</div>

Have you tried the `JSON` node?

Put it just after the `MQTT` node and before you do any thing else.  
But note: the payloads will be slightly modified.

---

<div class="post-metadata">

**Author:** ![Exit2Studios](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/exit2studios/32/10998_2.png) [@Exit2Studios](https://discourse.nodered.org/u/Exit2Studios)\
**Post date:** [22 August 2019 21:36 UTC](https://discourse.nodered.org/t/passing-mqtt-message-issues/14612/14 "2019-08-22T21:36:05Z")

</div>

![29%20PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/1797a04d5f490c956711da75f3b444fe80c73579.png)

Gets rid of the quotation marks, which I assume is changing it to a numeric value? Still no result in HA. Feel like I'm getting closer though?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 August 2019 21:53 UTC](https://discourse.nodered.org/t/passing-mqtt-message-issues/14612/15 "2019-08-22T21:53:23Z")

</div>

I'm not at my desk so excuse the brevity.

Sorry, but what "HA" value?

---

<div class="post-metadata">

**Author:** ![Exit2Studios](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/exit2studios/32/10998_2.png) [@Exit2Studios](https://discourse.nodered.org/u/Exit2Studios)\
**Post date:** [22 August 2019 23:06 UTC](https://discourse.nodered.org/t/passing-mqtt-message-issues/14612/16 "2019-08-22T23:06:46Z")

</div>

Sorry, Home Assistant

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [23 August 2019 05:07 UTC](https://discourse.nodered.org/t/passing-mqtt-message-issues/14612/17 "2019-08-23T05:07:12Z")

</div>

> [@Exit2Studios](#):
>
> Still no result in HA. Feel like I'm getting closer though?

Have you found out yet what format HA wants?  
Have you checked the topic names are identical?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [24 August 2019 22:54 UTC](https://discourse.nodered.org/t/passing-mqtt-message-issues/14612/18 "2019-08-24T22:54:37Z")

</div>

(Me again)

Looking at what you said in this post:

> [@Exit2Studios](#):
>
> TypeError [ERR\_INVALID\_ARG\_TYPE]: The "list[1]" argument must be one of type Array, Buffer, or Uint8Array. Received type string

Honestly: try adding the `JSON` node between the `MQTT` receive node and what ever is next.

I am really sure it will fix the error.

I spent a lot of time messing about with something very much like this and Nick O'Leary mentioned the `JSON` node all fell into place from there on.  
(For that problem)

As @ukmoose asked: What does HA want?
