Usage is as follows (don't use this code literally as is; it has a sneaky bug - see http://forum.micropython.org/viewtopic. ... 1068#p6460):
Code: Select all
import untplib
c=untplib.NTPClient()
resp=c.request('0.uk.pool.ntp.org', version=3, port=123)
print("Offset is ", resp.offset)
from machine import RTC
import time
rtc = RTC()
print("Adjusting clock by ", resp.offset, "seconds")
rtc.init(time.localtime(time.time() + resp.offset))
I've put the library and sample code here: https://github.com/andrewmk/untplib
Andrew
[[Edit: changed name of repository to untplib to avoid confusion]]