kopia lustrzana https://github.com/micropython/micropython-lib
ntptime: Allow overriding default NTP timeout.
The default 1 second timeout is sometimes not enough depending on the host and network latencies. This patch makes timeout configurable.pull/549/head^2
rodzic
8503017e3b
commit
900dd1c61b
|
@ -11,6 +11,8 @@ except:
|
||||||
|
|
||||||
# The NTP host can be configured at runtime by doing: ntptime.host = 'myhost.org'
|
# The NTP host can be configured at runtime by doing: ntptime.host = 'myhost.org'
|
||||||
host = "pool.ntp.org"
|
host = "pool.ntp.org"
|
||||||
|
# The NTP socket timeout can be configured at runtime by doing: ntptime.timeout = 2
|
||||||
|
timeout = 1
|
||||||
|
|
||||||
|
|
||||||
def time():
|
def time():
|
||||||
|
@ -19,7 +21,7 @@ def time():
|
||||||
addr = socket.getaddrinfo(host, 123)[0][-1]
|
addr = socket.getaddrinfo(host, 123)[0][-1]
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
try:
|
try:
|
||||||
s.settimeout(1)
|
s.settimeout(timeout)
|
||||||
res = s.sendto(NTP_QUERY, addr)
|
res = s.sendto(NTP_QUERY, addr)
|
||||||
msg = s.recv(48)
|
msg = s.recv(48)
|
||||||
finally:
|
finally:
|
||||||
|
|
Ładowanie…
Reference in New Issue