wifiesp32sleep-mode

ESP32 Why WiFi connection causes "Brownout detector was triggered" after deep sleep


When reconnecting to WiFi after waking up from deep sleep, an error "Brownout detector was triggered" is thrown causing the partial restart of the ESP. The setup phase is then done again, but now WiFi succeed to connect.

How to properly reestablish a WiFi connection after a deep sleep?

    #include <WiFi.h>
    #include "esp_wifi.h"
    
    #define SSID    "myssid"
    #define PASS    "ssidpass"
    
    #define uS_TO_S_FACTOR 1000000ULL   /* Conversion factor for micro seconds to seconds */
    #define TIME_TO_SLEEP  10           /* Time ESP32 will go to sleep (in seconds) */
    
    RTC_DATA_ATTR int boot_count = 0;
    
    void setup() {
      Serial.begin(115200);
      delay(200);
      
      print_wakeup_reason();
      Serial.print("Boot count: "); Serial.println(boot_count);
    
      Serial.println("WiFi connection");
      WiFi.begin(SSID, PASS);
      int try_count = 0;
      while (WiFi.status() != WL_CONNECTED && try_count < 10) {
          try_count++;
          delay(1000);
          Serial.println("Connection...");
      }
      Serial.println("WiFi connected");
    
      WiFi.disconnect();
      esp_wifi_stop();
      Serial.println("Sleeping in 1s ...");
      delay(1000);
    
      esp_deep_sleep(TIME_TO_SLEEP * uS_TO_S_FACTOR);  
    }
    
    void loop() {
    }
    
    void print_wakeup_reason(){
      esp_sleep_wakeup_cause_t wakeup_reason;
    
      wakeup_reason = esp_sleep_get_wakeup_cause();
    
      switch(wakeup_reason)
      {
        case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
        case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
        case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break;
        case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;
        case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break;
        default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break;
      }
    }

Corresponding serial monitor message :

ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5816
entry 0x400806ac
Wakeup was not caused by deep sleep: 0
Boot count: 0
WiFi connection
Connection...
WiFi connected
Sleeping in 1s ...
ets Jun  8 2016 00:22:57

rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5816
entry 0x400806ac
Wakeup caused by timer
Boot count: 0
WiFi connection

Brownout detector was triggered

ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5816
entry 0x400806ac
Wakeup was not caused by deep sleep: 0
Boot count: 0
WiFi connection
Connection...
WiFi connected
Sleeping in 1s ...
ets Jun  8 2016 00:22:57

rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5816
entry 0x400806ac
Wakeup caused by timer
Boot count: 0
WiFi connection

Brownout detector was triggered

I'm using a ESP-WROOM-32 (Chip is ESP32D0WDQ6 (revision 1)), on GNU Linux, with Arduino IDE 1.8.13, card library : Espressif System 1.0.4


Solution

  • In the search for the lowest consumption, I finally proceeded to various optimizations. And I came to deep sleep the ESP after disabling WiFi, and I take the ESP out of deep sleep with the WiFi still disabled. I reactivate the WiFi before using it. The ESP wake-up time is not a problem, low consumption is my priority. And it works without a problem, without even using the first solution I posted.