← index #682PR #5122
Related · high · value 2.285
QUERY · ISSUE

ntptime Feature request: Would like to have the ntp server configurable

openby hagenbuchopened 2023-06-14updated 2023-06-28

The timeserver is hardcoded n ntptime.py:

host = "pool.ntp.org"

I would prefer to have this configurable, for several reasons:

  • There might only be a local network where the node is
  • DNS might not be available in some cases and under some error conditions
  • One might as well use a numeric values
  • Coordinated time might be more important than a real interconnection for embedded devices often involved with logging.

I'm sorry I have no idea (yet) where to start to create a full pull request..

1 comment
massimosala · 2023-06-28

Hi Andreas

It isn't hard-coded.

It is weird they don't put the 'host' as a parameter of the function, but you can do this:

import ntptime
ntptime.host = "your choice"
ntptime.settime()
CANDIDATE · PULL REQUEST

esp8266/modules/ntptime.py: Add param for NTP host

closedby sleepymurphopened 2019-09-19updated 2019-10-04

The current ntplib.py has its timeserver hardcoded as pool.ntp.org. This patch adds a host parameter so users can supply an alternative.

In our case, we wanted to use our university's timeserver since it's close, and we wanted to refer to it by IP address to avoid an extra round-trip for the DNS lookup.

You can also explicitly pass None to use the default, in case you're passing in another variable.

# Example usage
ntptime.time()    # default, pool.ntp.org
ntptime.time(host="ntp.uit.no")    # UiT timeserver
ntptime.time(host=None)    # default, pool.ntp.org

Hope you find it useful.

Cheers!

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied