recursive clock uopdate - ESP32

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
guyd
Posts: 81
Joined: Fri Jul 20, 2018 6:08 am

recursive clock uopdate - ESP32

Post by guyd » Mon Jul 23, 2018 6:55 am

Hi,

My device, based on ESP32 with Micropython, needs a RTC to run scheduled tasks.
Using

Code: Select all

import ntptime
ntptime.settime()
RTC is updating, but I wish to update it every several time. Since it is not Linux, or Python - I wish to do so with minimum resources.
what is best for that ?

Guy

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: recursive clock uopdate - ESP32

Post by pythoncoder » Tue Jul 24, 2018 5:43 am

I can see no particular resource problem with periodically running

Code: Select all

ntptime.settime()
There is probably no alternative as NTP is likely to be your only source of an accurate reference.

However you do have to be careful about updating a clock which is being used to schedule events. This is because your clock no longer increments in a monotonic fashion: it can jump forwards or backwards by an arbitrary amount. Without care this can cause events to be scheduled twice or to be omitted.
Peter Hinch
Index to my micropython libraries.

guyd
Posts: 81
Joined: Fri Jul 20, 2018 6:08 am

Re: recursive clock uopdate - ESP32

Post by guyd » Tue Jul 24, 2018 6:50 am

pythoncoder wrote:
Tue Jul 24, 2018 5:43 am
I can see no particular resource problem with periodically running

Code: Select all

ntptime.settime()
There is probably no alternative as NTP is likely to be your only source of an accurate reference.

However you do have to be careful about updating a clock which is being used to schedule events. This is because your clock no longer increments in a monotonic fashion: it can jump forwards or backwards by an arbitrary amount. Without care this can cause events to be scheduled twice or to be omitted.
Thank you for your answer.
since I need it as an automated process - I was wondering if using thread and sleep for 6 hours between updates, is light enough - since on top of the clock update prcoess, there is the scheduled tasks process.

Can you please explain why jumps in time can occur ? what would be the reason for that ? fail update process ?

carsten
Posts: 15
Joined: Wed Aug 16, 2017 3:08 pm

Re: recursive clock uopdate - ESP32

Post by carsten » Tue Jul 24, 2018 11:09 am

pythoncoder wrote:
Tue Jul 24, 2018 5:43 am
However you do have to be careful about updating a clock which is being used to schedule events. This is because your clock no longer increments in a monotonic fashion: it can jump forwards or backwards by an arbitrary amount. Without care this can cause events to be scheduled twice or to be omitted.
Can this cause problems with uasyncio?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: recursive clock uopdate - ESP32

Post by pythoncoder » Tue Jul 24, 2018 12:31 pm

It won't cause problems with official uasyncio as it does not use the RTC as its timebase.

But if your own code checks for a time of (say) 3.10.00 to trigger an event, you could have a problem. Say the RTC time was 3.09.55 and an update caused it to be corrected to 3.10.05 the time of 3.10.00 would never occur. A correction in the reverse direction would cause it to occur twice.
Peter Hinch
Index to my micropython libraries.

guyd
Posts: 81
Joined: Fri Jul 20, 2018 6:08 am

Re: recursive clock uopdate - ESP32

Post by guyd » Tue Jul 24, 2018 1:10 pm

pythoncoder wrote:
Tue Jul 24, 2018 12:31 pm
It won't cause problems with official uasyncio as it does not use the RTC as its timebase.

But if your own code checks for a time of (say) 3.10.00 to trigger an event, you could have a problem. Say the RTC time was 3.09.55 and an update caused it to be corrected to 3.10.05 the time of 3.10.00 would never occur. A correction in the reverse direction would cause it to occur twice.
Oh, now I get it.
TNX

carsten
Posts: 15
Joined: Wed Aug 16, 2017 3:08 pm

Re: recursive clock uopdate - ESP32

Post by carsten » Wed Jul 25, 2018 6:19 pm

pythoncoder wrote:
Tue Jul 24, 2018 12:31 pm
It won't cause problems with official uasyncio as it does not use the RTC as its timebase.

But if your own code checks for a time of (say) 3.10.00 to trigger an event, you could have a problem. Say the RTC time was 3.09.55 and an update caused it to be corrected to 3.10.05 the time of 3.10.00 would never occur. A correction in the reverse direction would cause it to occur twice.
Thank you for your answer!

Post Reply