Is Thingspeak MQTT reliable?
Show older comments
I have a couple of NodeMCUs that are sending data to TS every 30 minutes since 2018, with no issues, using ThingSpeak API. These days I tried to give MQTT a chance, so I changed my code in order to use ThingSpeak MQTT broker to publish my data. I followed the code example from this page.
The result is really disappointing: while the devices are still sending the data every 30 minute (with no error codes) the data is not published every time, so I have my chart full of "holes". Sometimes they are published once an hour, some other every 2 hours, randomly.
I have checked the code many times, but it is quite straight-forward, so I have the suspect that the QoS=0 is not giving the best results.
Answers (1)
Vinod
on 30 Dec 2020
0 votes
I just tried this example for a few hours, admittedly it is on a Raspberry Pi, and had reliable results with no "holes" in the data. If your code on the NodeMCU is substantially different, can you share that so we may use that to help you troubleshoot? (Please mask/delete any API keys or credentials in your code you share)
12 Comments
Fabio Marzocca
on 30 Dec 2020
Vinod
on 30 Dec 2020
A few things I see straight away without trying to put this code on a device:
- The loop() seems to have nothing. Most examples of the library call client.loop() inside of the Arduino loop()
- There seems to be no delay() whatsoever when publishing to ThingSpeak in the sendDataToTS() function. With a free account, one can update a channel every 15 seconds at most. With a paid license, one can increase that rate to up to once per second. Knowingly exceeding rates allowed by your license type borders on abuse of service and might result in the channel ingest getting throttled.
- There's a lot of libraries used. It is not clear to me that one of them is not using up all free memory and causing runtime errors that result in unpredictable behavior.
My recommendation is to simplify the sketch -- perhaps start with one of the examples with the PubSubClient library - and add on the necessary parts from there. Remember to ensure that your sendDataToTS() has adequate delays so you don't end up hammering the service.
Fabio Marzocca
on 30 Dec 2020
Edited: Fabio Marzocca
on 30 Dec 2020
Fabio Marzocca
on 30 Dec 2020
Fabio Marzocca
on 30 Dec 2020
Thanks for clarifying it - I missed the fact that you have circuitry that ensures the request only gets sent every 30 minutes.
When I look at the server logs, I definitely see that not all requests ~30 minutes apart are coming in. There are gaps in the timestamps of the received message; Serveral of them didn't even make it to our HiveMQ server. Below is a screenshot of the timestamps in US EDT of requests to update your channel from the latter half of 12/30. I've marked some of the missing slots.
This could be on account of the QoS 0, the PubSubClient's robustness in the network conditions, etc.
I'm not sure I have any more suggestions, other than to try connecting your device over wired connection rather than WiFi. Then again, that might not be possible with the NodeMCUs you're using.
One other suggesiton is to possibly try a C program on your PC or a (wired) Raspberry Pi that is programmed to do something similar to your code on the NodeMCU to confirm that is not seeing dropped points.

Fabio Marzocca
on 31 Dec 2020
Fabio Marzocca
on 31 Dec 2020
Fabio Marzocca
on 31 Dec 2020
Fabio Marzocca
on 31 Dec 2020
Edited: Fabio Marzocca
on 31 Dec 2020
Fabio Marzocca
on 2 Jan 2021
Communities
More Answers in the ThingSpeak Community
Categories
Find more on Write Data to Channel in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!