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

Moderator: igrr

User avatar
By chupo_cro
#58872 Just put:

Code: Select allWiFi.forceSleepWake();

before

Code: Select allWiFi.begin();

and everything will again work as before using the deep sleep mode. Adding delay will not help.

I am not sure why there is a need for forceSleepWake() but I had the same problem and after hours of experimenting I found that method is the solution.

I've made a question about that just a few minutes ago but am still waiting my post to be moderated.
User avatar
By Joseph!
#60384 Dear chupo_cro,

Thank you for our answer, I didn't see it until now! Sorry! I must say that the ESP8266 I was using worked pretty fine during 17 days without any crash, sending MAC, temperature and voltage to a server every two minutes. It was working pretty good, but in the day 17 (although having 4.0V in the battery, a 7600mAh LiPo one) it crashed and never woke up again until I forced a reset. I don't really know why, nothing changed all this time (no Wifi or battery or whatever).

By the way, I was here again to tell you about the performance of the device. I have included the WiFi.forceSleepWake() before the WiFi.begin() and also I have closed the WiFiClient and the WiFi connection before going to DeepSleep, but not sure if it is needed:

Code: Select all  WiFi.forceSleepWake();
  if(WiFi.status() != WL_CONNECTED){
    WiFi.begin(ssid, password);
  }
  int j = 0;
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    j++;
    if (j == 50) {
      break;
    }
    //Serial.print(".");
  }

  //Serial.println(WiFi.localIP());
  //Serial.println(WiFi.status());
  if (WiFi.status() == WL_CONNECTED) {
    mac = WiFi.macAddress();
    WiFiClient client;
    const int httpPort = 80;
    if (!client.connect(host, httpPort)) {
      client.stop();
      delay(100);
      WiFi.disconnect();
      delay(100);
      ESP.deepSleep(120000000, WAKE_RF_DEFAULT);
      delay(1000);
      //return;
    }

    if ((err = dht11.read(hum, temp)) == 0)   /
    {

    }
    else
    {
      temp = 99;
    }
    int vcc = ESP.getVcc();
    String vc;
    vc = String((int)vcc);
    webString = String((int)temp); // Arduino has a hard time with float to string
    String url = whatever;

    client.print(String("GET ") + url + webString + String("&mac=") + mac + String("&vc=") + vc + " HTTP/1.1\r\n" + "Host:" + host  + "\r\n" + "Connection: close\r\n\r\n");
    delay(100);
    client.stop();
    delay(100);
    //1200000000us son 20 minutos
  }
  if(WiFi.status() == WL_CONNECTED){
    WiFi.disconnect();
  }
  delay(1000);
  ESP.deepSleep(120000000, WAKE_RF_DEFAULT);
  delay(100);



I will see what happens now. I am not sure if I can do the client.close() statement if the client doesn't connect to the host, but it is working fine by now... Do you see anything wrong in it?