Deepsleep causes a reset of time
Posted: Fri Aug 03, 2018 3:24 pm
I am trying to resolve why the time gets reset after around 4200 seconds while it is in deep sleep.
If you track it, the time tracks fine between waking up and going to deep sleep, except that it goes back to zero sometime after it reaches the 4200 mark.
This piece of code demonstrates it:
time_t now2;
time(&now2);
Serial.print("Time - ");
Serial.println(now2);
esp_deep_sleep(1000000LL * 10); //10 seconds
//delay(10000);
Run this, and you will see how the time (seconds in this case) keeps on advancing till after 4200 where it goes back to 0.
Now if you comment out the esp_deep_sleep command and put in the delay for 10 seconds, the time keeps on going up an up for as long as the unit has been running.
So deep_sleep is resetting the time after it reaches over 4200.
I have also used the code gettimeofday(&timeNew, NULL), and then get the seconds with timeNew.tv_sec. That does exactly the same. I have never seen the time reset while it has been running, only when it is in deep sleep. And when it wakes up, the time is not zero, but always on the low end. So the time has reset during deep sleep and restarted.
If you track it, the time tracks fine between waking up and going to deep sleep, except that it goes back to zero sometime after it reaches the 4200 mark.
This piece of code demonstrates it:
time_t now2;
time(&now2);
Serial.print("Time - ");
Serial.println(now2);
esp_deep_sleep(1000000LL * 10); //10 seconds
//delay(10000);
Run this, and you will see how the time (seconds in this case) keeps on advancing till after 4200 where it goes back to 0.
Now if you comment out the esp_deep_sleep command and put in the delay for 10 seconds, the time keeps on going up an up for as long as the unit has been running.
So deep_sleep is resetting the time after it reaches over 4200.
I have also used the code gettimeofday(&timeNew, NULL), and then get the seconds with timeNew.tv_sec. That does exactly the same. I have never seen the time reset while it has been running, only when it is in deep sleep. And when it wakes up, the time is not zero, but always on the low end. So the time has reset during deep sleep and restarted.