Deepsleep causes a reset of time

Robertho
Posts: 4
Joined: Thu Aug 02, 2018 2:02 pm

Deepsleep causes a reset of time

Postby Robertho » 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.

Robertho
Posts: 4
Joined: Thu Aug 02, 2018 2:02 pm

Re: Deepsleep causes a reset of time

Postby Robertho » Sun Aug 05, 2018 7:17 am

Something else I have noticed is that the time can also go backwards. Looking at it one instance it will be say 2200 seconds. Then it sleeps for 10 minute, and when it wakes up, the time is 2180.

Robertho
Posts: 4
Joined: Thu Aug 02, 2018 2:02 pm

Re: Deepsleep causes a reset of time

Postby Robertho » Fri Aug 10, 2018 12:02 pm

Here is something interesting from this post:

https://arduino.stackexchange.com/quest ... s-rollover

Note on micros(): Everything said here about millis() applies equally to micros(), except for the fact that micros() rolls over every 71.6 minutes, and the setMillis() function provided below does not affect micros().

71.6 minutes equals 4296 seconds. The problem I have is that my time is resetting every 4296 seconds. But I am using the millis() (indirectly), not micros().

My theory on this is that there is a bug in the sleep code that manages the RTC. When it does the reset on micros(), it is also doing the reset on millis(). The reset of millis() doesn't happen if there is no deep sleep.

Any idea where I can look?

Robertho
Posts: 4
Joined: Thu Aug 02, 2018 2:02 pm

Re: Deepsleep causes a reset of time

Postby Robertho » Fri Aug 10, 2018 12:23 pm

Here is another post that to me looks like the same problem:

https://github.com/espressif/arduino-esp32/issues/572

The problem here is that the user found that he couldn't deepsleep for longer than an hour. I ran into this with my project as well. The longest you can deepsleep for is the 4200 seconds mark. Same thing. So the timer that takes care of the deepsleep is resetting after the 4200 mark, thus messing up your deep sleep time.

For my project, the longest I allow it to sleep is for 1 hour. After 1 hour, it wakes up, adds to the RTC_DATA_ATTR that I have setup for this, and when it gets to 8 hours, it does what it is supposed to do.

There shouldn't be a 4200 seconds limit to deep sleep if you look at the data type being passed to the function. In the above post it is assumed that the data type is to blame. I don't think so. I think it is the same thing. The RTC timer resets, and that sets the end of deepsleep.

Who is online

Users browsing this forum: Bing [Bot] and 114 guests