ESP8266 response error -301 | ESP Wi-Fi | 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
ESP8266 response error -301
No permission to create posts
February 9, 2019
9:15 am
Avatar
grb
New Member
Members
Forum Posts: 3
Member Since:
February 9, 2019
sp_UserOfflineSmall Offline

Hello,
I am using ESP8266 Wroom-02 and the latest version library: ThingSpeak ver.1.4.3 for Arduino. I'm using a simple example from the library.
When I use the function: delay (20000) everything works fine. But when instead of the delay function it uses the sleep function: ESP.deepSleep (20,000,000) the thingspeak server returns error -301 (Failed to connect to ThingSpeak)
I receive update successful connection ( code 200) a reliable connection once every several dozen attempts.

A part of my sketch:

...
void loop() {

...

// Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different
// pieces of information in a channel. Here, we write to field 1.

int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey);

// Check the return code
if(x == 200){
Serial.println("Channel update successful.");
}
else{
Serial.println("Problem updating channel. HTTP error code " + String(x));
}

delay(20000); // Wait 20 seconds before sending a new value *******************- this works well

// ESP.deepSleep(20000000); //*************************************************- this does'n work!

}

Anyone have an idea to solve the problem?

BR
Greg

February 9, 2019
9:27 pm
Avatar
Vinod

MathWorks
Members
Forum Posts: 305
Member Since:
May 1, 2016
sp_UserOfflineSmall Offline

I think the esp.deepsleep() is closing the tcp socket too soon. Try inserting a delay() before you put the device into deep sleep.

February 10, 2019
12:13 pm
Avatar
grb
New Member
Members
Forum Posts: 3
Member Since:
February 9, 2019
sp_UserOfflineSmall Offline

Tnx for answer!
I don't close the connection too quickly, because the condition: if (x == 200) ... is earlier.
Deepsleep follows after this condition - so the answer is already known.

BR
Greg

February 10, 2019
10:31 pm
Avatar
Vinod

MathWorks
Members
Forum Posts: 305
Member Since:
May 1, 2016
sp_UserOfflineSmall Offline

Sorry, I didn't notice that you were reading the response code back.

My guess is after the esp wakes up from deep sleep, it doesn't have sufficient time to establish the wifi connection. Try putting a 1 second delay after the deep sleep and seeing if you get a 301.

February 11, 2019
6:23 am
Avatar
grb
New Member
Members
Forum Posts: 3
Member Since:
February 9, 2019
sp_UserOfflineSmall Offline

Hi,
After wake up ESP, I have wifi connection - I checked it.

I noticed a certain dependence. If the sleep time is more than 4 minutes, everything works fine! For example - I send data every 5 minutes and it works 100%.
If the deepsleep time is less than 5 minutes, the server very often returns error -301.
Does the server have some time to automatically shut down the tcpip connection?

February 11, 2019
8:55 am
Avatar
Vinod

MathWorks
Members
Forum Posts: 305
Member Since:
May 1, 2016
sp_UserOfflineSmall Offline

ThingSpeak never sends a 301 back to an update request. The 301 could be from somewhere else in the chain, possibly a router or gateway.

Have you tried assigning you esp8266 a static IP in your router config settings?

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
23 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:

Sahil Nair, ahancity, samexpert, Senseworks, h-kasiri, kleifimmakly

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457