ThingSpeak MQTT omits first field.

Using the ESP-IDF, I am experiencing an issue where I am posting to my thingspeak channel and the first field is omitted. I am recieving data on from subsequent points except for the first one. The payload string for testing is below, creating random numbers to send.
asprintf(&data, "field1=%d&field2=%d&field3=%d&field4=%d", rand()%120, rand()%120, rand()%120, rand()%140);
What is being sent in one post is:
data: field1=60&field2=87&field3=44&field4=111
A JSON export of the data recieved by thingspeak is:
{"created_at":"2020-09-09T19:33:32Z","entry_id":343,"field1":null,"field2":"63","field3":"117","field4":"115\"}","field5":null,"field6":null,"field7":null,"field8":null}]}
Can anyone comment on what can be done to fix this?

Answers (1)

Vinod
Vinod on 10 Sep 2020
Edited: Vinod on 10 Sep 2020
I think it is because you are missing an important separator in your request. Try modifying to
asprintf(&data, "?field1=%d&field2=%d&field3=%d&field4=%d", rand()%120, rand()%120, rand()%120, rand()%140);
Note the "?" before the "field1=".

6 Comments

Hi Vinod, I have changed my code as per your suggestion to no avail.
size = asprintf(&data, "?field1=%d&field2=%d&field3=%d&field4=%d", rand()%120, rand()%120, rand()%120, rand()%140);
The topic I am publishing is as such:
channels/XXXXXXX/publish/XXXXXXXXXXXXXX/
Followed by this:
?field1=60&field2=108&field3=112&field4=76
Thingspeak shows this:
{"created_at":"2020-09 -10T15:45:57Z","entry_id":797,"field1":null,"field2":"108","field3":"112","field4":"76\"}","field5":null,"field6":null,"field7":null,"field8":null}
Next steps?
I apologize -- I assumed you were using the REST API to update your ThingSpeak channels. My suggestion was with this assumption.
Based on the information you have provided, it looks like you are using MQTT API to update your ThingSpeak channel. Have you tried this example?
I am not using the Arduino IDE to develop this system. I am using the MQTT API to communicate to thingspeak MQTT servers over TCP.
Let me know once you tried the example and you can confirm all 8 fields are publishing. Then you can compare the example to your code and understand the difference.
Once again, not using Arduino. I have found that I can publish different combinations of the data string to thingspeak with only the first field being omitted, regardless of the position in the data string.
field5=0&field1=003&field2=021&field3=030&field4=116
In this string, field5, field2, field3, and field4 will show correct data, where field1 t will show as null in the JSON output of thingspeak.
Any ideas?
I was able to use MQTT.fx client to publish all fields. Try as I might, I was unable to reproduce this issue.
Can you confirm with a 3rd party client that publishes to your channel work fine? If you can see the correct publish happening with MQTT.fx, for example, then I would start looking at your code or even the MQTT client you are using to see if it is the cause for what you're seeing.

Sign in to comment.

Communities

More Answers in the  ThingSpeak Community

Categories

Products

Asked:

on 9 Sep 2020

Commented:

on 16 Sep 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!