Put esp32 to sleep

This commit is contained in:
Zuckerberg 2023-11-13 22:45:25 -07:00
parent fb30109f42
commit 0ba0101ff6

View File

@ -6,10 +6,13 @@
#include "network.h"
void fetchAndDrawImage();
void hibernate_and_restart();
const char *ssid = WIFI_SSID;
const char *password = WIFI_PASSWORD;
#define HIBERNATE_TIME_SEC 120 // hibernate time in seconds
const char *serverName = "http://192.168.3.133:8080/fetchImage";
void setup()
@ -60,6 +63,21 @@ void fetchAndDrawImage() {
}
http.end();
hibernate_and_restart();
}
void hibernate_and_restart() {
// Go to sleep and wake up later
// Configure wake up source as timer
esp_sleep_enable_timer_wakeup(HIBERNATE_TIME_SEC * 1000000);
// Enter hibernation mode
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_SLOW_MEM, ESP_PD_OPTION_OFF);
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_FAST_MEM, ESP_PD_OPTION_OFF);
esp_deep_sleep_start();
}
void loop()