Notifications
Clear all

Deep Sleep ESP32 for hours ?

4 Posts
2 Users
2 Reactions
4,257 Views
(@genki)
Member
Joined: 4 years ago
Posts: 10
Topic starter  

Hi,

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 ***

void goToDeepSleep()
{
Serial.println("Going to sleep...");
esp_sleep_enable_timer_wakeup(DEEP_SLEEP_TIME * 60L * 1000000L);
esp_deep_sleep_start();
}

At my wits end with this.

Anyone have any ideas for the values please, what am I doing wrong here ?

Thanks

Genki


   
Quote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 
Posted by: @genki

what am I doing wrong here

I think you may want to specify the 64-bit unsigned int type for the microseconds :

https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/system/sleep_modes.html#_CPPv429esp_sleep_enable_timer_wakeup8uint64_t

Maybe something like :

uint64_t u64SleepLength = DEEP_SLEEP_TIME * 60L * 1000000L;
esp_sleep_enable_timer_wakeup(u64SleepLength);

Eric


   
Genki reacted
ReplyQuote
(@genki)
Member
Joined: 4 years ago
Posts: 10
Topic starter  

Hi ZeFerby,

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.

Thanks !

Genki

 


   
ReplyQuote
(@genki)
Member
Joined: 4 years ago
Posts: 10
Topic starter  

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");
Serial.flush();
esp_deep_sleep_start();

Thanks

Genki!


   
HAL9000 reacted
ReplyQuote