M5Paper: can't reconnect to WiFi after 'esp_light_sleep' (on power)

  • I'm working on an app for M5Paper which will spend most of it's time asleep or shutdown; waking every few hours to check data from the internet (and depending on the results, either update the display or don't).

    So the loop function attempts to connect to WiFi and load the data, then disconnects; then either updates the display or doesn't; then attempts to shutdown. If the M5paper is on power, then the M5.shutdown command has no effect, so the code then calls esp_light_sleep_start.

    When it wakes up, if the unit is on battery (so it's a complete start-up) it all works as normal. If it is on power (so it's just resuming after 'light sleep') then it fails to connect to WiFi.

    If I replace the call to esp_light_sleep_start with a call to delay for the same period, then it connects repeatedly without issue.

    A summary of the code (this is using the WiFiMulti (ESP8266WiFiMulti) library by Markus Sattler, dated 16.05.2015, to support working across several locations with different WiFi availability):

    WiFiMulti wifiMulti;
    boolean connectToWifi()
      uint8_t tRes;
      for (int i = 0; i < NUMWIFINETWORKS; i++) {
        wifiMulti.addAP(aWifiNetworks[i], aWifiPasswords[i]);
      Serial.printf("Connecting Wifi... trying %d networks\n", NUMWIFINETWORKS);
      if ((tRes = wifiMulti.run()) == WL_CONNECTED) {
        Serial.print("WiFi connected ");
        Serial.print("IP address: ");
        return true;
      } else {
        Serial.printf("Failed to connnect to WiFi: %d.\n", tRes);
      return false;
    void disconnectFromWifi()
      Serial.println("disconnecting from WiFi");

    Evidently something in the course of esp_light_sleep_start 'breaks' something that the WiFi needs, so I need to reset it. But I don't know what, or how I can reset it!

    Can anyone shed any light?