esp8266/modules/ntptime.py: Always close socket, and set day-of-week.
Fixes issue #5189.
This commit is contained in:
parent
580a2656d1
commit
79ab82ea77
|
@ -17,9 +17,11 @@ def time():
|
|||
NTP_QUERY[0] = 0x1b
|
||||
addr = socket.getaddrinfo(host, 123)[0][-1]
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
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))
|
||||
|
|
Loading…
Reference in New Issue