Peter Hsi in Discussions
上次活动时间: 2024-7-29

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 Unreliable update ThingSpeak channel from Arduino MCU board -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. https://github.com/mathworks/thingspeak-arduino 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); 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. writefields
Gabriel in MATLAB Answers
上次活动时间: 2022-11-7

When uploading 3 fields using multifield update (writeFields) is that counted as one message or 3? I'm asking regarding the 8,200 messages/day. Thanks.
Subtil Songeur in MATLAB Answers
上次活动时间: 2021-12-1

I get the data from my 2x dth11 (2x temp and 2x humidity) sensor and no error with this code, but thingspeak receved no data and i get only one loop. Any one see what wrong? #include <Ethernet.h> #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros #include "DHT.h" #define DHT1PIN 10 // what pin we're connected to #define DHT2PIN 9 // Uncomment whatever type you're using! #define DHT1TYPE DHT11 // DHT 11 #define DHT2TYPE DHT11 // DHT 11 DHT dht1(DHT1PIN, DHT1TYPE); DHT dht2(DHT2PIN, DHT2TYPE); byte mac[] = { 0xDE, 0xAD, 0xBE, 0xXX, 0xXX, 0xXX }; // Set the static IP address to use if the DHCP fails to assign IPAddress ip(192, 168, X, XXX); IPAddress myDns(192, 168, X, X); EthernetClient client; unsigned long myChannelNumber = XXXXXX; const char * myWriteAPIKey = "XXXXXXXXXXXXXXX"; // Initialize our values int number1 = 0; int number2 = random(0,100); int number3 = random(0,100); int number4 = random(0,100); void setup() { Ethernet.init(10); // Most Arduino Ethernet hardware Serial.begin(115200); //Initialize serial while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo native USB port only } // start the Ethernet connection: Serial.println("Initialize Ethernet with DHCP:"); if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); // Check for Ethernet hardware present if (Ethernet.hardwareStatus() == EthernetNoHardware) { Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); while (true) { delay(1); // do nothing, no point running without Ethernet hardware } } if (Ethernet.linkStatus() == LinkOFF) { Serial.println("Ethernet cable is not connected."); } // try to congifure using IP address instead of DHCP: Ethernet.begin(mac, ip, myDns); } else { Serial.print(" DHCP assigned IP "); Serial.println(Ethernet.localIP()); } // give the Ethernet shield a second to initialize: delay(1000); ThingSpeak.begin(client); // Initialize ThingSpeak Serial.println("DHT11 Fonctionnel"); dht1.begin(); dht2.begin(); } void loop() { // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) float t1 = dht1.readTemperature(); float h1 = dht1.readHumidity(); float t2 = dht2.readTemperature(); float h2 = dht2.readHumidity(); // check if returns are valid, if they are NaN (not a number) then something went wrong! if (isnan(t1) || isnan(h1)) { Serial.println("Failed to read from DHT #1"); } else { Serial.print("Temperature entrée: "); Serial.print(t1); Serial.print(" *C "); Serial.print(" Humidity entrée: "); Serial.print(h1); Serial.println(" %\t"); } if (isnan(t2) || isnan(h2)) { Serial.println("Failed to read from DHT #2"); } else { Serial.print("Temperature sortie: "); Serial.print(t2); Serial.print(" *C "); Serial.print(" Humidity sortie: "); Serial.print(h2); Serial.println(" %\t"); } // set the fields with the values ThingSpeak.setField(1, dht1.readTemperature()); delay(10000); ThingSpeak.setField(2, dht1.readHumidity()); delay(10000); ThingSpeak.setField(3, dht2.readTemperature()); delay(10000); ThingSpeak.setField(4, dht2.readHumidity()); delay(10000); // write to the ThingSpeak channel // write to the ThingSpeak channel int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); if(x == 200){ Serial.println("Mise a jour du Canal."); } else{ Serial.println("Problem updating channel. HTTP error code " + String(x)); } // change the values number1++; if(number1 > 99){ number1 = 0; } number2 = random(0,100); number3 = random(0,100); number4 = random(0,100); delay(20000);// Wait 20 seconds to update the channel again }
Barnard Richards in MATLAB Answers
上次活动时间: 2021-6-18

my code int x = ThingSpeak.writeFields(myChannelNumber[ChID], myWriteAPIKey[ChID]);

关于 ThingSpeak

The community for students, researchers, and engineers looking to use MATLAB, Simulink, and ThingSpeak for Internet of Things applications. You can find the latest ThingSpeak news, tutorials to jump-start your next IoT project, and a forum to engage in a discussion on your latest cloud-based project. You can see answers to problems other users have solved and share how you solved a problem.