8000 net/ntptime/ntptime.py: Allow overriding default NTP timeout. · micropython/micropython-lib@8a17626 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 8a17626

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 8a17626

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

micropython/net/ntptime/ntptime.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
except:
1010
import struct
1111

12+
1213
# The NTP host can be configured at runtime by doing: ntptime.host = 'myhost.org'
1314
host = "pool.ntp.org"
15+
# The NTP socket timeout can be configured at runtime by doing: ntptime.timeout = 1.0
16+
timeout = 1.0
1417

1518

1619
def time():
@@ -19,7 +22,7 @@ def time():
1922
addr = socket.getaddrinfo(host, 123)[0][-1]
2023
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
2124
try:
22-
s.settimeout(1)
25+
s.settimeout(timeout)
2326
res = s.sendto(NTP_QUERY, addr)
2427
msg = s.recv(48)
2528
finally:

0 commit comments

Comments
 (0)
0