MQTT publish to Thingspeak with a JSON payload
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mazlum Serkan Ürkmez
le 11 Fév 2023
Réponse apportée : Christopher Stapels
le 15 Fév 2023
MQTT publishing Payload format of the client in my IoT device is JSON. It is able to publish only a single property like {"temperature":25} . This {"name":<value>} JSON format can not be changed on my device. So it can not be converted to a plain text something like field1=25 or 25 . How to publish JSON payload like from my device to Thindspeak ?
I tried converting the "name" to "field1" in my device's payload and published to channel feed, Thingspeak doesn't accept as a valid data, no visualisation on dashboard;
Topic: channels/<channelID>/publish
Payload: {"field1":25}
Or I tried with the "temperature" in my devices payload and published to channel field feed, it doesn't work, either;
Topic: channels/<channelID>/publish/fields/field1
Payload: {"temperature":25}
Instead of my Device, When I tried one of those with a PC MQTT client sofware, works to my channel!
Topic: channels/<channelID>/publish
Payload: field1=25
Topic: channels/<channelID>/publish/fields/field1
Payload: 25
How to work with JSON format ?
Notes:
- I can't use my write API KEY in MQTT publish. I always tried to add KEY at the end of the topics line like channels/<channelID>/publish/<writeAPIKEY> . When published to this topic that a connection error occurs. I can't see documentation how using API keys in MQTT API . Is it related with my JSON issue ?
- My Channel is private.
0 commentaires
Réponse acceptée
Christopher Stapels
le 15 Fév 2023
Two ways to automatically trigger code:
React (on Data insert)
TimeControl (group data processed since last job)
0 commentaires
Plus de réponses (2)
Christopher Stapels
le 13 Fév 2023
You are correct that ThingSpeak requires you to have the specific format fieldx= in your payload. You can see all the correct parameters in the MQTT API documentation.
Could you consider using the REST API?
Publishing to a single field might make it possible. Here the payload is taken completely without using fieldx=1. However, ThingSpeak might take the field value as the whole string i.e.'"temperature":25'. Then the field plots wouldnt work automatically, But you could then write a MATLAB script (in ThingSpeak) that will strip away the word "temperature" and then plot the values.
The present version of the MQTT API does not use the API key in the topic or payload. Do not add an API key, the connection will be refused. I assume that since you were successful with the desktop version that your device is set up properly.
0 commentaires
Voir également
Catégories
En savoir plus sur Write Data to Channel dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!