ESP32 and erratic updating problems | ThingSpeak Apps | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
ESP32 and erratic updating problems
No permission to create posts
August 30, 2020
2:41 pm
Avatar
ningster2
New Member
Members
Forum Posts: 2
Member Since:
August 30, 2020
sp_UserOfflineSmall Offline

I use esp32 and two sensors. The esp32 wakes up from deep sleep every 2 minutes and updates 2 channels using ThingSpeak lib. I keep have erratic updating problems, i.e. one or more successful updates followed by one or more -304 error codes, then good again and bad again...it's been going on for for 2 days without any apparent pattern or cause. Below is the relevant arduino codes:

ThingSpeak.begin(client);

ThingSpeak.setField(1, f1);
ThingSpeak.setField(2, f2);
httpError = ThingSpeak.writeFields(CHANNEL_ID, CHANNEL_API_KEY);
if(httpError == 200){
Serial.println("Data sent successful. " + String(httpError));
}else{
Serial.println("Problem updating channel. HTTP error code " + String(httpError));
}
delay(15500);//free account data rate 1/15 seconds
ThingSpeak.setField(3, httpError); //previous thingspeak return code
//ThingSpeak.setField(4, NoWifiCount);

httpError = ThingSpeak.writeFields(CHANNEL_ID, CHANNEL_API_KEY);
if(httpError == 200){
Serial.println("Channel udate successful. " + String(httpError));
}else{
Serial.println("Problem updating channel. HTTP error code " + String(httpError));
}

August 31, 2020
2:26 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 861
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

From the library doc -304 means the server timed out waiting for a reply. I think this means your network connection is insufficient. Can you try the same code on a different network, or move closer to the hub?

FYI, MATLAB answers is the preferred location for ThingSpeak Community support.

September 1, 2020
8:21 pm
Avatar
ningster2
New Member
Members
Forum Posts: 2
Member Since:
August 30, 2020
sp_UserOfflineSmall Offline

Thanks for the explanation. It makes perfect sense. I added a while loop to give it a few tries when return !=200. This basically solved the missing data problem. It's an acceptable work around for my application. Thanks again.

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
21 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

anis, 43994554AKS, suda, marisol, qkpham, SANGAMNATH B

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457