Not the usual "deep sleep not resetting" issue - I have GPIO 16 connected to RST so that is working.
I hope I can explain this clearly; sorry for the length.
I have a sketch like this, working as expected:
const int WIFI_TIMEOUT = 10;// 10 seconds
void setup() {
Serial.begin(115200);
WiFi.begin("my_ssid", "my_key");// connect to wifi AP
int i = 0;
while (WiFi.status() != WL_CONNECTED) {
delay(100);// sleep for 100ms
Serial.print(".");
i++;
if (i >= WIFI_TIMEOUT*10) {// connection timed out
Serial.println("Failed to establish wifi connection. Sleeping.");
ESP.deepSleep(30000000, RF_DEFAULT);// sleep for 30 seconds and reset
}
}
WiFiClient client;
if (!client.connect(dataServerName.c_str(), PORT)) {
Serial.println("HTTP connection failed");
} else {// connection successful
// send PUT request to the server
// https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html
client.println(String("PUT ") + URL + "/store HTTP/1.1");
client.println(String("Host: ") + "myhost.com");
client.println("Connection: close");
client.println("Content-Type: application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.println(String(strPayload.length()));
client.println();// blank line means end of headers
client.println(strPayload);// add payload
}
}
void loop() {
// do some stuff
Serial.println("Sleeping now...");
ESP.deepSleep(30000000, RF_DEFAULT);// sleep for 30 seconds and reset
}
All this code does is:
- establish a WiFi connection to my access point
- establish an HTTP connection to a server and send an HTTP PUT request
- enter deep sleep for 30 seconds
This works as expected; every 30 seconds the ESP initialises, establishes a wifi connection, and sends a HTTP POST request with some data to a server. It then goes to sleep for 30 seconds and repeats.
The problem I have encountered is if the WiFi access point is UNAVAILABLE at an stage, it will wake up, fail to establish a connection, and go to sleep for 30 seconds.
Once that has happened even once, the ESP will fail to establish a WiFi connection to the access point again until the ESP is physically powered off and back on again. Not even physically resetting with the onboard reset switch will work. It will continually timeout establishing a WiFi connection.
Has anybody seen this behaviour before? Is it just my board? I have tried substituting RF_DEFAULT for RF_CAL but it doesn't seem to make any difference.
Regards
David