esp8266/modules/ntptime.py: Always close socket, and set day-of-week.

Fixes issue #5189.
pull/5202/head
Damien George 2019-10-10 18:05:56 +11:00
rodzic 580a2656d1
commit 79ab82ea77
1 zmienionych plików z 7 dodań i 6 usunięć

Wyświetl plik

@ -17,10 +17,12 @@ def time():
NTP_QUERY[0] = 0x1b
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)
msg = s.recv(48)
s.close()
try:
s.settimeout(1)
res = s.sendto(NTP_QUERY, addr)
msg = s.recv(48)
finally:
s.close()
val = struct.unpack("!I", msg[40:44])[0]
return val - NTP_DELTA
@ -31,5 +33,4 @@ def settime():
import machine
import utime
tm = utime.localtime(t)
tm = tm[0:3] + (0,) + tm[3:6] + (0,)
machine.RTC().datetime(tm)
machine.RTC().datetime((tm[0], tm[1], tm[2], tm[6] + 1, tm[3], tm[4], tm[5], 0))