Unreliable update ThingSpeak channel from Arduino MCU board

Peter Hsi on 28 Jul 2024
Latest activity Reply by Christopher Stapels on 29 Jul 2024

I use "x = ThingSpeak.writeFields(myChannelNumber1, myWriteAPIKey1);" in my code to update the ThingSpeak channel. 4 fields are associated with this channel. This statement is executed about once every 5 minutes.
Roughly 60% of the time, I got an error message "HTTP error code -301". The other 40% of time the channel update is successful. What does the "HTTP error code -301" mean? Any suggestion on how to improve the success rate of the channel update
Christopher Stapels
Christopher Stapels on 29 Jul 2024
-301 is network connectivity. It probably means the device is not getting a strong enough signal. You can try moving closer to the access point, try a different network, or consider adding an antenna. When you are sucessfully connected, it is uaully possible to measure RSSI, and you could write it to your channel and see.below -85 starts getting risky.
Peter Hsi
Peter Hsi on 29 Jul 2024
Thanks Chris for your answer. I add a field to report rssi signal of WiFi. So far, it showed about -70 to -74 dB.
I did observe an intersting fact - I remove 2 lines of code to setStatus() between the setField() code and writeField() code ( see listing below). This change seems to dramatically improve the successful ThingSpeak channel update rate ( from ~60% to over 95%). Not sure why?
Code:
.........
// set the fields
ThingSpeak.setField(1, vbat);
ThingSpeak.setField(2, moist);
ThingSpeak.setField(3, temp);
ThingSpeak.setField(4, humid);
ThingSpeak.setField(5, rssi_wifi);
// set the status
// myStatus = String("4 sensors");
// ThingSpeak.setStatus(myStatus);
// write to ThingSpeak channels
x = ThingSpeak.writeFields(myChannelNumber1, myWriteAPIKey1);
Christopher Stapels
Christopher Stapels on 29 Jul 2024
wow, thats an interesting result. Is it possible that there is offending data in the myStatus variable?
-70 to -74 should be totally fine, I have a bunch of devices out in my yard that regularly do ok from -70 to -80.
If you are using an Arduino, perhaps you are using some intermediary to make the wifi conenction (like esp8266, ESP 32, etc?) If so, id look at the buffer sizes, perhaps they are being exceeded when you add in the status.