esp8266/scripts/ntptime: Allow to override NTP server.

This is not part of public API, variable name may change, or it can be
replaced with a function.
This commit is contained in:
Paul Sokolovsky 2016-05-30 19:16:05 +03:00
parent 480159ca8b
commit 225562d915

View File

@ -10,10 +10,12 @@ except:
# (date(2000, 1, 1) - date(1900, 1, 1)).days * 24*60*60
NTP_DELTA = 3155673600
host = "pool.ntp.org"
def time():
NTP_QUERY = bytearray(48)
NTP_QUERY[0] = 0x1b
addr = socket.getaddrinfo('pool.ntp.org', 123)[0][-1]
addr = socket.getaddrinfo(host, 123)[0][-1]
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(1)
res = s.sendto(NTP_QUERY, addr)