Skip to content

Commit be5c711

Browse files
committed
net/ntptime/ntptime.py: 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 0c5880d commit be5c711

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

micropython/net/ntptime/ntptime.py

+3-1
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 = 1.0
15+
timeout = 1.0
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)