After noticing the D1 has a lot of time drift over 24 hours (10 or more mins), I changed my code to the below, checking NTP once every hour which has solved the drift problem.
My question is more of a check on whether I am solving this problem in (nearly) the most efficient way or is there other methods of keeping time with less drift? Is this level of drift pretty standard for a D1?
thanks for any comments / advice
Code: Select all
import tm1637
from machine import Pin
nsw = tm1637.TM1637(clk=Pin(12), dio=Pin(14))
qld = tm1637.TM1637(clk=Pin(04), dio=Pin(00))
import ntptime
import time
import utime
ntptime.settime()
nsw.brightness(0)
qld.brightness(0)
ntptime.host = "time.google.com"
x = 0
while True:
nswclock_hour = utime.localtime(utime.mktime(utime.localtime()) + 11*3600)[3]
nswclock_min = utime.localtime(utime.mktime(utime.localtime()) + 11*3600)[4]
qldclock_hour = utime.localtime(utime.mktime(utime.localtime()) + 10*3600)[3]
qldclock_min = utime.localtime(utime.mktime(utime.localtime()) + 10*3600)[4]
if nswclock_min == 01 and x == 0:
ntptime.settime()
x += 1
print('Time corrected at ', nswclock_hour)
if nswclock_min == 02:
x = 0
nsw.numbers(nswclock_hour, nswclock_min)
qld.numbers(qldclock_hour, qldclock_min)