The deepsleep state seems to reset the RTC, so I'm trying to create a minimalist way to get time from a server until other sleep states or ntp are implemented on this board.
In the unix port of micropython, this (based on discussion at http://stackoverflow.com/questions/1266 ... -in-python) works:
Code: Select all
from usocket import socket, AF_INET, SOCK_DGRAM, getaddrinfo from ustruct import unpack, calcsize NTP_PACKET_FORMAT = "!12I" NTP_DELTA = 2208988800 # 1970-01-01 00:00:00 NTP_QUERY = '\x1b' + 47 * '\0' addr=getaddrinfo('pool.ntp.org', 123)[-1] s=socket( AF_INET, SOCK_DGRAM) s.sendto(NTP_QUERY.encode('utf-8'),addr) msg, address = s.recvfrom(1024) unpacked = unpack(NTP_PACKET_FORMAT, msg[0:calcsize(NTP_PACKET_FORMAT)]) print(unpacked + float(unpacked) / 2**32 - NTP_DELTA)
Does anyone have insight into why this is failing and possible workarounds?