Deep Sleep ESP32 for hours ?
I am able to deep sleep my ESP32 for short periods (minutes) but not hours.
Anyone have some code to sleep the ESP32 for days ? weeks ?
This code works, and I can sleep the ESP32 for 15 minutes, but if I increase the value then it does not work.
// How many minutes the ESP should sleep
#define DEEP_SLEEP_TIME 15 <---- DOES NOT WORK IF I INCREASE VALUE FOR HOURS e.g 120 ***
Serial.println("Going to sleep...");
esp_sleep_enable_timer_wakeup(DEEP_SLEEP_TIME * 60L * 1000000L);
At my wits end with this.
Anyone have any ideas for the values please, what am I doing wrong here ?
what am I doing wrong here
I think you may want to specify the 64-bit unsigned int type for the microseconds :
Maybe something like :
uint64_t u64SleepLength = DEEP_SLEEP_TIME * 60L * 1000000L;
Thanks for your help, you have pointed me in a good direction.
I think the value that I'm passing into esp_sleep_enable_timer_wakeup() is wrong, either the wrong variable type or too large a number for it.
I'm going to play around and report back here.
Guys I forgot to update here. Got this working by changing the Variable type to UL. I guessing that it did not like the 64bit types.
#define uS_TO_S_FACTOR 1000000UL /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP 43200 /* Time ESP32 will go to sleep (in seconds) */
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
Serial.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP / 60) + " Minutes");