10000 ntptime: Allow overriding default NTP timeout. · micropython/micropython-lib@900dd1c · GitHub
[go: up one dir, main page]

Skip to content

Commit 900dd1c

Browse files
iabdalkaderdpgeorge
authored andcommitted
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.
1 parent 8503017 commit 900dd1c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

micropython/net/ntptime/ntptime.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
# The NTP host can be configured at runtime by doing: ntptime.host = 'myhost.org'
1313
host = "pool.ntp.org"
14+
# The NTP socket timeout can be configured at runtime by doing: ntptime.timeout = 2
15+
timeout = 1
1416

1517

1618
def time():
@@ -19,7 +21,7 @@ def time():
1921
addr = socket.getaddrinfo(host, 123)[0][-1]
2022
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
2123
try:
22-
s.settimeout(1)
24+
s.settimeout(timeout)
2325
res = s.sendto(NTP_QUERY, addr)
2426
msg = s.recv(48)
2527
finally:

0 commit comments

Comments
 (0)
0