It has a rechargeable battery that runs the ESP32 module when the main power is not present.
It has a FET that turns off all peripherals when the main power is not present.
I have confirmed that the FET is really off.
Everything works as expected (goes to sleep, wakes up when power returns, etc.)
Am I missing anything in putting the device into deep sleep?
Code: Select all
#define SLEEPING_PIN 14
#define SLEEPING_PIN_MASK (1ULL << SLEEPING_PIN)
static RTC_DATA_ATTR struct timeval sleep_enter_time;
//********************* MAIN ******************************
void app_main(void)
{
uint32_t strap = DPORT_REG_READ(GPIO_STRAP_REG);
ESP_LOGI("STRAPPING","Strapping register: %08lX", strap);
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
switch(cause) {
case ESP_SLEEP_WAKEUP_GPIO:
ESP_LOGI("wakeup","GPIO wakeup");
break;
case ESP_SLEEP_WAKEUP_EXT1:
ESP_LOGI("wakeup","EXT1 Wakeup");
struct timeval now;
gettimeofday(&now, NULL);
int sleep_time_ms = (now.tv_sec - sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - sleep_enter_time.tv_usec) / 1000;
ESP_LOGI("wakeup","We slept in deep sleep for %dms",sleep_time_ms);
break;
case ESP_SLEEP_WAKEUP_UNDEFINED:
ESP_LOGI("wakeup","Undefined Wakeup");
break;
default:
ESP_LOGI("wakeup","Unknown wakeup code: %d",(int)cause);
break;
}
gpio_reset_pin(SLEEPING_PIN);
gpio_set_direction(SLEEPING_PIN,GPIO_MODE_INPUT);
esp_sleep_enable_ext1_wakeup(SLEEPING_PIN_MASK,ESP_EXT1_WAKEUP_ANY_LOW);
//esp_sleep_enable_timer_wakeup(10000000); // 10 second wakeup
while(1) {
int sleeping = gpio_get_level(SLEEPING_PIN);
ESP_LOGI("sleeping","sleeping: %d",sleeping);
if( sleeping ) {
ESP_LOGI("sleeping","Going to sleep");
vTaskDelay( pdMS_TO_TICKS(1000));
struct timeval now;
gettimeofday(&now, NULL);
sleep_enter_time = now;
esp_deep_sleep_start();
}
else {
ESP_LOGI("sleeping","Not Sleeping");
}
vTaskDelay( pdMS_TO_TICKS(1000));
}