https://toitlang.org/ logo
automatic light sleep
# help
a
Hey all, I'm planning to build a battery powered device, but it needs to stay connected to wifi and have low latency reconnects. I saw there is a light sleep which is availabe under power management. Any plan to support that [automatic light sleep](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/power_management.html) ?
Copy code
c
#include "esp_pm.h"

// ... other includes and setup

void app_main(void) {
    esp_pm_config_esp32_t config = {
        .max_freq_mhz = 80, // or 160, depending on your needs
        .min_freq_mhz = 10, // minimum frequency for the clock
        .light_sleep_enable = true
    };
    esp_err_t result = esp_pm_configure(&config);

    if (result == ESP_OK) {
        // Configuration successful
    } else {
        // Handle error
    }
}
f
It already exists: https://libs.toit.io/esp32/library-summary#pm-configure(3%2C0%2C0%2Cenable-light-sleep%2Cmax-frequency-mhz%2Cmin-frequency-mhz) However, I think that any battery-based device needs to bring the esp32 into deep-sleep. Light sleep doesn't save that much energy.
Note that light-sleep might need a different sdkconfig (and thus a different envelope).
If it does, please let me know, and I can maybe add such a configuration to our https://github.com/toitlang/envelopes
a
Light sleep doesn't save that much energy. According to sources on the internet, it should get down to 2-5 mA
f
I'm probably just wrong. Please go ahead and test what is there. If you are missing things, let me know and I will try to help/fix it.