Not responsive after several hundred sleep/wake cycles

hristesp
Posts: 10
Joined: Wed Oct 11, 2023 2:49 pm

Not responsive after several hundred sleep/wake cycles

Postby hristesp » Wed Feb 04, 2026 2:33 pm

Microcontroller: ESP32-C3-MINI-1

A device we’re using collects, connects to WiFi, collects and sends sensor data of WiFi, then enters deep sleep.

After several sleep/wake cycles (between 30-600 recorded) devices, some devices stop behaving as expected and are not connecting to WiFi, potentially in a state that could be a brown-out.

I have attached an image of the current consumption during a wake-period.

Expected behaviour:

The device wakes up every hour and over the course of 9-17 seconds connects to WiFi, sends sensor data and battery level over WiFi to a back-end. The device can also be woken within the hour deep sleep duration by a button press.

Observed behaviour:

The device wakes up every hour and over the course of 9-17 seconds connects to WiFi, sends sensor data and battery level over WiFi to a back-end, however at unreliable periods does not send WiFi, and is unresponsive to button press.

Plugging the device to charge, even momentarily enables the device to behave as normal.

It is unknown at this point if the device begins its unexpected behaviour on waking, or on sleeping.

After the device is recovered, the battery appears to have discharged at a faster rate (drawing 1.8mA) than it would do in a deep-sleep state (~34uA).


Code

Some of the code snippets around preparing for deep-sleep are shown below.

Code: Select all

void system_prepare_deep_sleep(void)
{
    ESP_LOGI(LOG_TAG, "Preparing for deep‑sleep…");

    // 2) Give CoAP a few seconds to fetch the manifest and fire the callback
    vTaskDelay(pdMS_TO_TICKS(2000));
    // DON’T sleep if OTA is active!
    extern volatile bool ota_in_progress;
    if (ota_in_progress)
    {
        ESP_LOGI(LOG_TAG, "OTA in progress – skipping deep sleep");
        return;
    }
  //adc1_deinit();
    led_set_rgb(0, 0, 0);
    ledc_stop(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 0);
    ledc_stop(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 0);
    
// Drive moisture/salinity power pins low and hold
    gpio_set_level(MOIST1_PWM_PIN, 0);
    gpio_set_level(MOIST2_PWM_PIN, 0);
    

// Stop sensor task and buses
    sensors_stop();
   
    sleep_pin_config(); // configure pins for deep sleep
                        
    ESP_LOGI(LOG_TAG, "Entering deep sleep now…");
    sleep_type = SLEEP_TYPE_AUTO_SLEEP;

    esp_sleep_enable_timer_wakeup(30000000); //one hour  
    esp_deep_sleep_enable_gpio_wakeup(1ULL << WAKEUP_GPIO,
                                      ESP_GPIO_WAKEUP_GPIO_LOW);
    peripherals_power_off();
    

    // 8) Finally, go to sleep
    esp_deep_sleep_start();
}



void enter_sleep_on_wifi_loss(void)
{
    sleep_pin_config(); // configure pins for deep sleep

    esp_sleep_enable_timer_wakeup(30000000); // 1 hour in microseconds
    esp_deep_sleep_enable_gpio_wakeup(1ULL << WAKEUP_GPIO,
                                      ESP_GPIO_WAKEUP_GPIO_LOW);
    vTaskDelay(pdMS_TO_TICKS(1));

    esp_deep_sleep_start();
}
Summary:

Is there anything in the following that looks like we should be implementing - such as a Watchdog that you would use?
Attachments
lowvoltagehigherduration (1).png
Image of power profiling during wake, WiFi connection and data transfer period
lowvoltagehigherduration (1).png (120.52 KiB) Viewed 310 times

mikemoy
Posts: 687
Joined: Fri Jan 12, 2018 9:10 pm

Re: Not responsive after several hundred sleep/wake cycles

Postby mikemoy » Thu Feb 05, 2026 4:53 am

Not sure about this as I dont use deep sleep. But I would also disable the wifi before sleeping.
I would think that leaving it enabled, when it comes back to life again there might be some weirdness.

Who is online

Users browsing this forum: Google [Bot] and 19 guests