修复 1. AGS10的TVOC 数据为准备就绪问题
2. ntp支持多次获取时间
3. mini的同步讯飞function
This commit is contained in:
@@ -6,21 +6,27 @@ import ustruct as struct
|
||||
# NTP_DELTA (date(2000, 1, 1) - date(1900, 1, 1)).days * 24*60*60
|
||||
NTP_DELTA=3155673600
|
||||
|
||||
def time(host="pool.ntp.org", utc=28800):
|
||||
NTP_QUERY = bytearray(48)
|
||||
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:
|
||||
del addr
|
||||
s.close()
|
||||
gc.collect()
|
||||
val = struct.unpack("!I", msg[40:44])[0]
|
||||
return utime.gmtime(val - NTP_DELTA + utc)
|
||||
def time(host="pool.ntp.org", utc=28800, times=5):
|
||||
for _ in range(times):
|
||||
try:
|
||||
NTP_QUERY = bytearray(48)
|
||||
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:
|
||||
del addr
|
||||
s.close()
|
||||
gc.collect()
|
||||
val = struct.unpack("!I", msg[40:44])[0]
|
||||
return utime.gmtime(val - NTP_DELTA + utc)
|
||||
except Exception as e:
|
||||
error = e
|
||||
utime.sleep(0.1)
|
||||
raise OSError('Error fetching network time', error)
|
||||
|
||||
# There's currently no timezone support in MicroPython, and the RTC is set in UTC time.
|
||||
def settime(times):
|
||||
|
||||
Reference in New Issue
Block a user