My device, based on ESP32 with Micropython, needs a RTC to run scheduled tasks.
Using
Code: Select all
import ntptime
ntptime.settime()
what is best for that ?
Guy
Code: Select all
import ntptime
ntptime.settime()
Code: Select all
ntptime.settime()
Thank you for your answer.pythoncoder wrote: ↑Tue Jul 24, 2018 5:43 amI can see no particular resource problem with periodically runningThere is probably no alternative as NTP is likely to be your only source of an accurate reference.Code: Select all
ntptime.settime()
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?pythoncoder wrote: ↑Tue Jul 24, 2018 5:43 amHowever 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.
Oh, now I get it.pythoncoder wrote: ↑Tue Jul 24, 2018 12:31 pmIt 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!pythoncoder wrote: ↑Tue Jul 24, 2018 12:31 pmIt 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.