Is this library compatible with any deep-sleep mode
Jorfuenst opened this issue · 3 comments
For example, ESP32 deep-sleep.
Thanks a lot.
It relies on millis()
Lines 250 to 253 in 6d0fc5e
which in turn uses:
system_get_time()
on ESP8266 (see nonos-sdk pdf, there's alsosystem_get_rtc_time
)esp_timer_get_time()
on ESP32, see docs
Both functions return time that is reset on deep sleep. So no, it's incompatible, you can use it, but it resets after deep sleep.
As "rtc clock", which continues to work in deep sleep mode, is too imprecise and unreliable (quartz oscillator is disabled in deep sleep), it requires sophisticated handling. Nodemcu has implementation for it, and it's quite complex.
I am having great luck using this time library with pwrDownMode() from Sleep_n0m1 library. I go into pwrDownMode ( "deep sleep" ) for 10 seconds and then I ADVANCE the millis() timer directly to account for the milliseconds lost during the sleep. Some forum posts say it's bad to do that, but it works in practice for me. YMMV
extern volatile unsigned long timer0_millis; //<<this line before setup() !
#include <Sleep_n0m1.h> //<<this line before setup() !
Sleep cpu_sleep; //<<this line before setup() !
//following in setup/loop:
cpu_sleep.pwrDownMode(); //set sleep mode
cpu_sleep.sleepDelay(10000); //actual sleep
noInterrupts ();
timer0_millis = millis()+9988L; //long int 9988
interrupts ();