Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By daveb1014
#52412 Hi all,

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:

Code: Select allconst 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
User avatar
By schufti
#52416 Hi,

according to datasheet
Code: Select all         RF_DEFAULT = 0,  //RF_CAL depends on init data from byte 108
         RF_CAL = 1,  //RF_CAL enabled causes large current drain after wake 170mA
         RF_NO_CAL = 2,  //RF_CAL disabled, small current drain after wake 75mA
         RF_DISABLED = 4  //RF disabled, smallest current drain after wake 15mA

with rf_default your luck depends on byte 108. what and however value is there, it might be suboptimal.

I use deepsleep such that after I detect an unsuccessfull wifi connection attempt, I do an immediate deepsleep with RF_CAL, if successfully making a connection I use RF_NO_CAL. Works for months now and even saves energy...