diff options
Diffstat (limited to 'ports/esp8266/modules/ntptime.py')
-rw-r--r-- | ports/esp8266/modules/ntptime.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/ports/esp8266/modules/ntptime.py b/ports/esp8266/modules/ntptime.py index 0f512100c..92ae6ab07 100644 --- a/ports/esp8266/modules/ntptime.py +++ b/ports/esp8266/modules/ntptime.py @@ -13,9 +13,10 @@ NTP_DELTA = 3155673600 # The NTP host can be configured at runtime by doing: ntptime.host = 'myhost.org' host = "pool.ntp.org" + def time(): NTP_QUERY = bytearray(48) - NTP_QUERY[0] = 0x1b + NTP_QUERY[0] = 0x1B addr = socket.getaddrinfo(host, 123)[0][-1] s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) try: @@ -27,11 +28,13 @@ def time(): val = struct.unpack("!I", msg[40:44])[0] return val - NTP_DELTA + # There's currently no timezone support in MicroPython, so # utime.localtime() will return UTC time (as if it was .gmtime()) def settime(): t = time() import machine import utime + tm = utime.localtime(t) machine.RTC().datetime((tm[0], tm[1], tm[2], tm[6] + 1, tm[3], tm[4], tm[5], 0)) |