# MQTT.FX Thingspeak

**URL:** <https://discourse.nodered.org/t/mqtt-fx-thingspeak/28830>\
**Category:** General\
**Created:** [23 June 2020 18:42 UTC](https://discourse.nodered.org/t/mqtt-fx-thingspeak/28830 "2020-06-23T18:42:37Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin10](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Martin10](https://discourse.nodered.org/u/Martin10)\
**Post date:** [23 June 2020 18:42 UTC](https://discourse.nodered.org/t/mqtt-fx-thingspeak/28830/1 "2020-06-23T18:42:37Z")

</div>

I try to do this project, but with DHT sensors, and i've got this error. Any help?  
[https://flows.nodered.org/flow/00e8c4223c3a4e6539b75a7541abfef2](https://flows.nodered.org/flow/00e8c4223c3a4e6539b75a7541abfef2)

![Function](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/7/5777e4198b5b437e258f8d0cc6c1a3339f91f0cf.jpeg)

 ![2020-06-23-193626_800x480_scrot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/7/a707e067001d03d1fcb2247ef0cf6e2f2b6f43d5.png)

I use MQTT.fx broker (With thingspeak) and all settings (pub/sub) in the broker are ok.Now i want to use node-red, to obtain sensor data and send it to thingspeak via mqtt protocol, using MQTT.fx broker. What i have to add to my flow, in order to do the job?

---

<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:** [23 June 2020 18:52 UTC](https://discourse.nodered.org/t/mqtt-fx-thingspeak/28830/2 "2020-06-23T18:52:35Z")

</div>

It looks like you are passing the message from the DHT node to the MQTT Function. Can you show the Debug output for the message coming out of the DHT node?

The error is because either `msg.payload.object` or `msg.payload.ambient` doesn't exist. If you can share what the message coming out of the DHT node looks like, we can narrow down which is causing the issue.

---

<div class="post-metadata">

**Author:** ![Martin10](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Martin10](https://discourse.nodered.org/u/Martin10)\
**Post date:** [23 June 2020 19:23 UTC](https://discourse.nodered.org/t/mqtt-fx-thingspeak/28830/3 "2020-06-23T19:23:50Z")

</div>

`msg.payload.object` and`msg.payload.ambient` exist in the MQTT Function node.  
I pass the message from the DHT node through MQTT Function node to the mqtt out node.

This pic shows dht debug

 ![2020-06-23-221212_800x480_scrot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/a/caf15d9e2de69837f7520ea6bd9dc61700eb63ff.png)

This pic shows the mqtt debug

 ![2020-06-23-221218_800x480_scrot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/3/f3fda37a37cf5d25d5efadbc91ef012e500a7e76.png)

---

<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:** [23 June 2020 19:29 UTC](https://discourse.nodered.org/t/mqtt-fx-thingspeak/28830/4 "2020-06-23T19:29:55Z")

</div>

In the first post, your screenshot showed an error of `Cannot read property toString of undefined` coming from the MQTT Function node that would have been caused by either `msg.payload.object` or `msg.payload.ambient` not existing.

In your more recent post, you've shared a completely different error - "Invalid topic" coming from the MQTT publish node, and the MQTT function node no longer appears in your flow at all.

So at this point, I'm not sure what issue you want help with.

If its the Invalid topic specified error, then that will be because the MQTT node hasn't been configured with a valid topic to publish to, or you are passing in an invalid value for `msg.topic`.

Your screenshot shows the output of the DHT node - but given you've changed the flow, that's irrelevant now. It looks like its the output of the Temp node that you are passing to the MQTT node - so that would be the message we'd need to see to understand better what you are doing.

---

<div class="post-metadata">

**Author:** ![Martin10](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Martin10](https://discourse.nodered.org/u/Martin10)\
**Post date:** [23 June 2020 19:35 UTC](https://discourse.nodered.org/t/mqtt-fx-thingspeak/28830/5 "2020-06-23T19:35:20Z")

</div>

Sorry for the error

 ![2020-06-23-223323_800x480_scrot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/7/4750054c51dc26f4ee362e67d6127cc40ee3df05.png)

---

<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:** [23 June 2020 20:20 UTC](https://discourse.nodered.org/t/mqtt-fx-thingspeak/28830/6 "2020-06-23T20:20:30Z")

</div>

Your `msg.payload` seems to be just `"26.00"`, so it does not have `msg.payload.object` or `msg.payload.ambient`. (Sorry if I misunderstood the discussion on a quick read).

---

<div class="post-metadata">

**Author:** ![Martin10](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Martin10](https://discourse.nodered.org/u/Martin10)\
**Post date:** [24 June 2020 18:34 UTC](https://discourse.nodered.org/t/mqtt-fx-thingspeak/28830/7 "2020-06-24T18:34:39Z")

</div>

`msg.payload.object` and `msg.payload.ambient` exist in the MQTT Function node.

---

<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:** [24 June 2020 18:35 UTC](https://discourse.nodered.org/t/mqtt-fx-thingspeak/28830/8 "2020-06-24T18:35:53Z")

</div>

No they don't exist. The debug shows your message doesn't contain those properties.

---

<div class="post-metadata">

**Author:** ![Martin10](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Martin10](https://discourse.nodered.org/u/Martin10)\
**Post date:** [24 June 2020 18:42 UTC](https://discourse.nodered.org/t/mqtt-fx-thingspeak/28830/9 "2020-06-24T18:42:41Z")

</div>

In the first pic i show the Function node content, may be they are not write properly ?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [24 June 2020 18:45 UTC](https://discourse.nodered.org/t/mqtt-fx-thingspeak/28830/10 "2020-06-24T18:45:46Z")

</div>

You might have written them in a function node but they don't exist in the message.

Look at your debug output. There NO msg.payload.object or msg.payload.ambient in the msg

That's why you get an error in the function (as Nick said)

---

<div class="post-metadata">

**Author:** ![Martin10](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Martin10](https://discourse.nodered.org/u/Martin10)\
**Post date:** [25 June 2020 14:19 UTC](https://discourse.nodered.org/t/mqtt-fx-thingspeak/28830/11 "2020-06-25T14:19:14Z")

</div>

How t fix it?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 June 2020 14:24 UTC](https://discourse.nodered.org/t/mqtt-fx-thingspeak/28830/12 "2020-06-25T14:24:12Z")

</div>

Feed the correct data into the function OR change the function to match whats going in.

Look at your debug node contents

There’s a great page in the docs that will explain how to use the debug panel to find the right path to any data item. [https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

---

<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:** [26 June 2020 12:37 UTC](https://discourse.nodered.org/t/mqtt-fx-thingspeak/28830/13 "2020-06-26T12:37:21Z")

</div>

Closing this thread because it has be continued here: [MQTT. Thingspeak](https://discourse.nodered.org/t/mqtt-thingspeak/28898/17)

---

<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:** [26 June 2020 12:37 UTC](https://discourse.nodered.org/t/mqtt-fx-thingspeak/28830/14 "2020-06-26T12:37:27Z")

</div>


