# Problems parsing MQTT data to dashboard

**URL:** <https://discourse.nodered.org/t/problems-parsing-mqtt-data-to-dashboard/15002>\
**Category:** General\
**Created:** [1 September 2019 14:36 UTC](https://discourse.nodered.org/t/problems-parsing-mqtt-data-to-dashboard/15002 "2019-09-01T14:36:18Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![pcborges](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@pcborges](https://discourse.nodered.org/u/pcborges)\
**Post date:** [1 September 2019 14:36 UTC](https://discourse.nodered.org/t/problems-parsing-mqtt-data-to-dashboard/15002/1 "2019-09-01T14:36:18Z")

</div>

Hi, I am new to Node-Red.  
I have a working Mosquitto server.  
ESP32 publishes two sensor data that are shown at Node\_Red debug flow:

 ![Flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/a86a3172f483479fcc9dcb6ffde0e8f617b3f4d1.jpeg)

Debug output was activated as follow:  
Plain from Mosquitto MQTT:

 ![JsonOnly](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/ac464e1352259a89d5e0e8cc4891aa18b3a99c7a.jpeg)

Converted to Javascript:  
{temperatura: object}  
{humidade: object}

Javascript then split:  
{value: 27}  
{value: 67}

\*\*\*New user can only post two pictures so I transcribed the last two:

Still I do not get data that would be suitable for submission to the dashboard.  
My goal is to have two gauges, one for temperatura and one for humidade.

Assistance welcome.  
Thanks  
Paulo

---

<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:** [1 September 2019 14:49 UTC](https://discourse.nodered.org/t/problems-parsing-mqtt-data-to-dashboard/15002/2 "2019-09-01T14:49:34Z")

</div>

mqtt -\> json node (or set the mqtt node to send a json message instead), remove the split node.

output will be something like

```auto
{temperatura:{value:27.00}}
{humidade:{value:59.00}}

```

connect the 2 gauge nodes to the json/mqtt node and in the value fields use:

`{{msg.payload.temperatura.value}}`  
`{{msg.payload.humdade.value}}`

Don't forget to take a look at [the cookbook](https://cookbook.nodered.org)

---

<div class="post-metadata">

**Author:** ![pcborges](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@pcborges](https://discourse.nodered.org/u/pcborges)\
**Post date:** [1 September 2019 14:55 UTC](https://discourse.nodered.org/t/problems-parsing-mqtt-data-to-dashboard/15002/3 "2019-09-01T14:55:08Z")

</div>

Dear backman2, thanks for your availability to assist.  
Only the json node:

 ![Only%20Json](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/1eab5faa25ad7f4dfc6b2f0d982bdc4a773f8fac.jpeg)

Not getting the expected result...  
What I am doing wrong?  
Thanks

---

<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:** [1 September 2019 14:56 UTC](https://discourse.nodered.org/t/problems-parsing-mqtt-data-to-dashboard/15002/4 "2019-09-01T14:56:07Z")

</div>

That is _the expected_ result, even easier to just set the mqtt node output to "a parsed JSON object", then you can remove the json node.

---

<div class="post-metadata">

**Author:** ![pcborges](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@pcborges](https://discourse.nodered.org/u/pcborges)\
**Post date:** [1 September 2019 15:01 UTC](https://discourse.nodered.org/t/problems-parsing-mqtt-data-to-dashboard/15002/5 "2019-09-01T15:01:09Z")

</div>

OK, did that, from MQTT (straight to debug as a "parsed JSON object")  
Get the same result as the previous picture.  
Now, you mean I can submit that to the dashboard as it is?

Remember I have 2 gauges, don't I have to use a split somewhere?  
Thanks

---

<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:** [1 September 2019 15:02 UTC](https://discourse.nodered.org/t/problems-parsing-mqtt-data-to-dashboard/15002/6 "2019-09-01T15:02:08Z")

</div>

As I indicated above, you can use the values directly in the gauge node.

Also read the [documentation](https://nodered.org/docs/user-guide/messages) how to work with json/messages

---

<div class="post-metadata">

**Author:** ![pcborges](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@pcborges](https://discourse.nodered.org/u/pcborges)\
**Post date:** [1 September 2019 15:09 UTC](https://discourse.nodered.org/t/problems-parsing-mqtt-data-to-dashboard/15002/7 "2019-09-01T15:09:07Z")

</div>

I am in the process of trying the gauge now...  
I have been reading some of these docs, your indication will sure help as well but as it was not working I decided to get some help on making it work. Once it works it also makes it more easy to see what went wrong.

Just a last one.  
Gauge is still in progress but you mean gauge will understand I actually have two variables to plot?  
Separately?  
Thanks

---

<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:** [1 September 2019 15:13 UTC](https://discourse.nodered.org/t/problems-parsing-mqtt-data-to-dashboard/15002/8 "2019-09-01T15:13:06Z")

</div>

Yes: 2 gauges, 2 different values, 1 mqtt node.  
The documentation explains the JSON message part, that is what is coming from the MQTT node.

The gauge node parses this message, thus if there is temperatura in there it will display it else it won't, same applies to the humidity.

---

<div class="post-metadata">

**Author:** ![pcborges](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@pcborges](https://discourse.nodered.org/u/pcborges)\
**Post date:** [1 September 2019 15:31 UTC](https://discourse.nodered.org/t/problems-parsing-mqtt-data-to-dashboard/15002/9 "2019-09-01T15:31:32Z")

</div>

OK, I have been to this doc already.  
My difficulty is to understand how to, for instance, Mosquitto sends temperatura data and humidade data at different moments.  
How do I know the data I am dealing with now is temperatura? How do I test it?  
Because if I want to do something else with this value I must know what is the data about.

Supose I want to publish back to Mosquito a, say, LED "on" when temperature is above, say, 30 degrees? You see, that is where I am still struggling.

Well, not only there...  
I linket MQTT node straight to Gauge and what I am getting is this:

 ![Gauge](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/7e4fc2a3f26c16564a053d2e0489daa2e033dc24.jpeg)

Thanks  
Paulo

---

<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:** [1 September 2019 15:38 UTC](https://discourse.nodered.org/t/problems-parsing-mqtt-data-to-dashboard/15002/10 "2019-09-01T15:38:30Z")

</div>

try setting the gauge like this

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/e09507145595a6a63321416e97e0d57f913af6d9.png)

---

<div class="post-metadata">

**Author:** ![pcborges](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@pcborges](https://discourse.nodered.org/u/pcborges)\
**Post date:** [1 September 2019 15:42 UTC](https://discourse.nodered.org/t/problems-parsing-mqtt-data-to-dashboard/15002/11 "2019-09-01T15:42:57Z")

</div>

Hi, thanks dceejay, it worked for temperatura...  
How do I get a separate gauge for humidade?

I mean, perhaps link another gauge at the same source and make it as you said just with humidade?

Great, I did that and it worked. Thanks

Thanks again...

---

<div class="post-metadata">

**Author:** ![pcborges](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@pcborges](https://discourse.nodered.org/u/pcborges)\
**Post date:** [1 September 2019 16:07 UTC](https://discourse.nodered.org/t/problems-parsing-mqtt-data-to-dashboard/15002/12 "2019-09-01T16:07:34Z")

</div>

HI again...  
It is working perfectly with a gauge with value= {{msg.payload.temperatura.value}} and a separate gauge with value={{msg.payload.humidade.value}} but the debug screen shows an error:  
"Type error: cannot read property 'value' of undefined" for both temperatura and humidade gauges.

My current flow is as below:

 ![new](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/49b3597186df1eac7deab235603737940ed125e5.jpeg)

MQTT node:  
Server: Mosquitto  
Topic: /devices/esp32devboard/#  
Output: auto-detect (string or buffer)  
Name: AllTopics

JSON  
Action: always convert to javascript object  
property: payload

Gauge  
Group: myGroup  
Label: Temperatura  
value format: {{msg.payload.temperatura.value}}

Gauge humidade is changed accordingly.

Thanks  
Paulo

---

<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:** [1 September 2019 16:26 UTC](https://discourse.nodered.org/t/problems-parsing-mqtt-data-to-dashboard/15002/13 "2019-09-01T16:26:07Z")

</div>

_edit_ I am incorrect, i will post a test flow.

Apologies, i made quick assumptions, the `undefined` error comes from the gauge node that doesn't accept other data than the one defined.

With this flow it should work, instead of using a "split", it contains 2 switch nodes that only passes data when either temperature or humidity exists. Replace the inject nodes with the mqtt node

```auto
[{"id":"5e695d79.c5a7f4","type":"ui_gauge","z":"50a9d0fb.ca78d","name":"","group":"9aa3571e.b6013","order":2,"width":0,"height":0,"gtype":"gage","title":"temperatura","label":"c","format":"{{msg.payload.temperatura.value}}","min":"-20","max":"50","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":686,"y":672,"wires":[]},{"id":"7030a7e6.81464","type":"ui_gauge","z":"50a9d0fb.ca78d","name":"","group":"9aa3571e.b6013","order":2,"width":0,"height":0,"gtype":"gage","title":"humidity","label":"%","format":"{{msg.payload.humidade.value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":676,"y":728,"wires":[]},{"id":"b8e3427b.68e8d","type":"inject","z":"50a9d0fb.ca78d","name":"{\"temperatura\":{\"value\":24}}","topic":"","payload":"{\"temperatura\":{\"value\":24}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":232,"y":672,"wires":[["dbb7cea4.d730d8","8ead371d.55a9d"]]},{"id":"514b08ba.318018","type":"inject","z":"50a9d0fb.ca78d","name":"{\"humidade\":{\"value\":52}}","topic":"","payload":"{\"humidade\":{\"value\":52}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":222,"y":728,"wires":[["8ead371d.55a9d","dbb7cea4.d730d8"]]},{"id":"8ead371d.55a9d","type":"switch","z":"50a9d0fb.ca78d","name":"humidity","property":"payload.humidade","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":480,"y":728,"wires":[["7030a7e6.81464"]]},{"id":"dbb7cea4.d730d8","type":"switch","z":"50a9d0fb.ca78d","name":"temperatura","property":"payload.temperatura","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":490,"y":672,"wires":[["5e695d79.c5a7f4"]]},{"id":"9aa3571e.b6013","type":"ui_group","z":"","name":"Default","tab":"76ec6942.7f7ab","disp":true,"width":"17","collapse":false},{"id":"76ec6942.7f7ab","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<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:** [1 September 2019 17:57 UTC](https://discourse.nodered.org/t/problems-parsing-mqtt-data-to-dashboard/15002/14 "2019-09-01T17:57:29Z")

</div>

@dceejay I am running NR beta, the `has key` option works nicely for this example 🙂 thanks for the implementation!

 ![45](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/d2ae99497ff5d6b9d8066a72024af6090bbff7c4.jpeg)

---

<div class="post-metadata">

**Author:** ![pcborges](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@pcborges](https://discourse.nodered.org/u/pcborges)\
**Post date:** [2 September 2019 01:41 UTC](https://discourse.nodered.org/t/problems-parsing-mqtt-data-to-dashboard/15002/15 "2019-09-02T01:41:41Z")

</div>

Hi, this one worked perfect.  
Thank you all for your contributions and effort.  
Regards  
Paulo

---

<div class="post-metadata">

**Author:** ![pcborges](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@pcborges](https://discourse.nodered.org/u/pcborges)\
**Post date:** [2 September 2019 01:44 UTC](https://discourse.nodered.org/t/problems-parsing-mqtt-data-to-dashboard/15002/16 "2019-09-02T01:44:58Z")

</div>

This "has key" would be perfect.  
Any information on when it will be available?  
Thanks  
Paulo
