# MQTT. Thingspeak

**URL:** <https://discourse.nodered.org/t/mqtt-thingspeak/28898>\
**Category:** General\
**Created:** [24 June 2020 15:39 UTC](https://discourse.nodered.org/t/mqtt-thingspeak/28898 "2020-06-24T15:39:40Z")\
**Posts on this page:** 19\
**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:** [24 June 2020 15:39 UTC](https://discourse.nodered.org/t/mqtt-thingspeak/28898/1 "2020-06-24T15:39:40Z")

</div>

Hi.  
Recently i made a flow, which allow me to sent sensor data to thingspeak via http.

 ![2020-05-31-220322_800x480_scrot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/4/e48e146ff2910398da23acadfc8cb05455b6a917.png)

But now i try to make a flow to help me sent sensor data to thingspeak via mqtt ([mqtt.thingspeak.com](http://mqtt.thingspeak.com)). Any help?

---

<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 15:42 UTC](https://discourse.nodered.org/t/mqtt-thingspeak/28898/2 "2020-06-24T15:42:14Z")

</div>

What do you need help with specifically? Add an MQTT node, configure it with whatever details thingspeak requires and then start passing it messages.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [24 June 2020 16:22 UTC](https://discourse.nodered.org/t/mqtt-thingspeak/28898/3 "2020-06-24T16:22:20Z")

</div>

This is now the third thread that you have asked this question, but so far you have not addressed the questions asked.  
To add to @knolleary's answer you want an MQTT Out node, not the mqtt server node that it seems you were trying to use previously.

---

<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:18 UTC](https://discourse.nodered.org/t/mqtt-thingspeak/28898/4 "2020-06-24T18:18:32Z")

</div>

I try this, but nothing.  
[https://flows.nodered.org/flow/00e8c4223c3a4e6539b75a7541abfef2](https://flows.nodered.org/flow/00e8c4223c3a4e6539b75a7541abfef2)  
Do I need an external server?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [24 June 2020 18:59 UTC](https://discourse.nodered.org/t/mqtt-thingspeak/28898/5 "2020-06-24T18:59:39Z")

</div>

did you cofigure the `mqtt-out` node in that flow?

also please stay on one thread until you solve that issue so that people aren't working at cross purposes.

---

<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 19:06 UTC](https://discourse.nodered.org/t/mqtt-thingspeak/28898/6 "2020-06-24T19:06:03Z")

</div>

Yes, i cofigure it

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [24 June 2020 19:12 UTC](https://discourse.nodered.org/t/mqtt-thingspeak/28898/7 "2020-06-24T19:12:32Z")

</div>

in that case, add a `mqtt-in` node and use the same credentials you used for the output and enter the same topic used in the `mqtt-out` node. connect that to a `debug` node and then add an `inject` node connected to the `mqtt-out` node. Deploy and press the inject. You should see a message in the debug log coming from the `debug` node attached to the `mqtt-in` node. This way you can see if your mqtt settings are working

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 June 2020 07:37 UTC](https://discourse.nodered.org/t/mqtt-thingspeak/28898/8 "2020-06-25T07:37:40Z")

</div>

> [@Martin10](#):
>
> Do I need an external server

You have an external broker (it is called a broker for mqtt not a server), it is Thingspeak.  
See the first line of [MQTT API - MATLAB & Simulink - MathWorks United Kingdom](https://uk.mathworks.com/help/thingspeak/mqtt-api.html)

---

<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 09:15 UTC](https://discourse.nodered.org/t/mqtt-thingspeak/28898/9 "2020-06-25T09:15:44Z")

</div>

I made some flow (the flow sends data but with thingspeak nodes and when i remove the mqtt node the data still transmits in the cloud, so it use http, i suppose) in which i have inject node which triggers the entire flow, do i need second?  
Do i need thingspeak node, and which on of them, because they are two types?  
Do i need some extra function nodes in combination with the one from the initial example?

 ![2020-06-24-000115_800x480_scrot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/4/f4e817de7c82825db0300b17ec416a15dc2fbc90.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 June 2020 09:57 UTC](https://discourse.nodered.org/t/mqtt-thingspeak/28898/10 "2020-06-25T09:57:45Z")

</div>

You don't appear to have considered @zenofmud's suggestion.

---

<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 10:02 UTC](https://discourse.nodered.org/t/mqtt-thingspeak/28898/11 "2020-06-25T10:02:11Z")

</div>

This is my old flow that i try to create before. I show you the flow to see what i've done so far. I wiil try the suggestion.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 June 2020 10:18 UTC](https://discourse.nodered.org/t/mqtt-thingspeak/28898/12 "2020-06-25T10:18:10Z")

</div>

> [@Martin10](#):
>
> Do i need thingspeak node, and which on of them, because they are two types?

Assuming you mean node-red-contrib-thingspeak and ditto42 then they are both years old with unaddressed issues against them. Decide whether you want to use one of them or MQTT and go that way, don't try and use more than one, there is no point. Personally I would use MQTT.

---

<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:** [26 June 2020 11:38 UTC](https://discourse.nodered.org/t/mqtt-thingspeak/28898/13 "2020-06-26T11:38:21Z")

</div>

I've made some flow and i've got this error from the function node.

 ![2020-06-26-142047_800x480_scrot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/7/c76c7cea202265314781e6626c64b57691191685.png)

The content of the function node is:  
 ![Function](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/7/5777e4198b5b437e258f8d0cc6c1a3339f91f0cf.jpeg)

When i edit mqtt broker do i have to fill the client ID, and with what ? User API Key?  
 ![MQTT API](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/0/502939d2035a4886a6a3e0d60e6f6d5ee74c6b42.jpeg)

 ![2020-06-26-142254_800x480_scrot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/f/efa8dea3c50a4e6581fefcdb8cd64b8de3073dd1.png)

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [26 June 2020 11:43 UTC](https://discourse.nodered.org/t/mqtt-thingspeak/28898/14 "2020-06-26T11:43:48Z")

</div>

You need to hide any credentials on screen shots before posting them to the forum

Otherwise bad people could do bad things with them ☹

---

<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 11:52 UTC](https://discourse.nodered.org/t/mqtt-thingspeak/28898/15 "2020-06-26T11:52:20Z")

</div>

@Martin10 this is exactly the same error you had in another thread.

The error `toString of undefined` means one of the values you are trying to use `toString` on is not defined.

In your function code you are calling `toString` on both `msg.payload.object` and `msg.payload.ambient`

Where are you setting `msg.payload.object` and `msg.payload.ambient`? What does the message look like that you are passing into this function? Does it have those properties set on it?

---

<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:** [26 June 2020 12:28 UTC](https://discourse.nodered.org/t/mqtt-thingspeak/28898/16 "2020-06-26T12:28:05Z")

</div>

I'm not good at programming. I just want to pass data from the DHT sensors to thingspeak via mqtt. This example i took from hire:  
[https://flows.nodered.org/flow/00e8c4223c3a4e6539b75a7541abfef2](https://flows.nodered.org/flow/00e8c4223c3a4e6539b75a7541abfef2)

---

<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:36 UTC](https://discourse.nodered.org/t/mqtt-thingspeak/28898/17 "2020-06-26T12:36:47Z")

</div>

Ok, so that flow works because the `mlx-sensor` node it uses creates a message containing `object` and `ambient` as properties.

You have a different message coming from the DHT node - so you need to understand the structure of that message and identify what properties are the ones you want to send to Thingspeak.

From the other thread, you did share a picture showing the Debug output for the node - [MQTT.FX Thingspeak](https://discourse.nodered.org/t/mqtt-fx-thingspeak/28830/5)

It appears you have `msg.payload` as the temperature reading and `msg.humidty` as the humidity.

So a starting point would be to replace `msg.payload.object` with `msg.payload` and replace `msg.payload.ambient` with `msg.humidity` in your Function node.

---

<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:** [26 June 2020 15:00 UTC](https://discourse.nodered.org/t/mqtt-thingspeak/28898/18 "2020-06-26T15:00:59Z")

</div>

Thank you very much [knolleary](https://discourse.nodered.org/u/knolleary), it works!

---

<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:** [25 August 2020 15:01 UTC](https://discourse.nodered.org/t/mqtt-thingspeak/28898/19 "2020-08-25T15:01:01Z")

</div>

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