From 0ba0101ff6fddc1a472293d922e64b24251b0642 Mon Sep 17 00:00:00 2001 From: Zuckerberg Date: Mon, 13 Nov 2023 22:45:25 -0700 Subject: [PATCH] Put esp32 to sleep --- firmware/src/main.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index ad6849e..643e4fd 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -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()