ESP32 deep sleep

kumart
Posts: 7
Joined: Thu Nov 30, 2017 8:24 pm

ESP32 deep sleep

Postby kumart » Fri Dec 01, 2017 7:23 am

Hey guys
I am using ESP32 with esp-idf on a ESP32 Thing from Sparkfun.
I‘d like to put the ESP32 into deep sleep when the device is not used, to save energy. The RTC should continue.
Once that worked well, but now if I wake it up with a special GPIO Pin, it makes a reset and I can‘t find the reason why.
Is there a possibility to wake up without any reset after deep sleep?
Thanks for your help!

ESP_Sprite
Posts: 9051
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32 deep sleep

Postby ESP_Sprite » Fri Dec 01, 2017 8:16 am

This is how deep sleep works, essentially. To get the low power use that deep sleep can give you, we have to shut down everything, including main memory. Because this, your program indeed effectively resets. You can still store state (variables, ...) in RTC memory, however, and you can use the data stored there to 'manually' get back to what you were doing.

kumart
Posts: 7
Joined: Thu Nov 30, 2017 8:24 pm

Re: ESP32 deep sleep

Postby kumart » Fri Dec 01, 2017 8:50 am

Thanks for your Reply.
The important thing is that i don't loose my time value when ESP32 goes to sleep.
I'm using the following code in main:
struct timeval current_time;
current_time.tv_sec = 1511791969;
current_time.tv_usec = 0;
settimeofday(&current_time, NULL); //to set the current date/time value
After every ten seconds, i run time() to update the current time.
How can i manage that the time does not be overwritten by the reset after deep sleep?
Is it possible to create a Reset-flag, store it to RTC Memory and if(flag) call time() instead of settimeofday() in main? Would that work?

ESP_Sprite
Posts: 9051
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32 deep sleep

Postby ESP_Sprite » Sat Dec 02, 2017 9:32 am

Actually, that should just work out of the box, given that you select the RTC as (part of) the time source (make menuconfig -> component config -> esp32 specific -> timer used for gettimeofday function). If you have that, can you post a dump of the serial output that happens when you go into deep sleep and the ESP32 wakes from that?

Ah, or maybe you mean how to check the CPU woke up from deep sleep instead of reset? You can use rtc_get_reset_reason for that. If rtc_get_reset_reason(0) == DEEPSLEEP_RESET, you're waking from deep sleep.

Who is online

Users browsing this forum: Majestic-12 [Bot] and 263 guests