Closed ridgy-b closed 2 years ago
Hi @ridgy-b
yes, it seems that dhcp_set_ntp_servers()
does not only initialize DHCP provided NTP servers, but also cleans out the rest.
and yes, the recommended usage is to
1) enable NTP over DHCP before getting the IP
2) set the static NTP servers after receiving the DHCP lease
As outlined in the IDF example: Ad 1) https://github.com/espressif/esp-idf/blob/229ed084847455da5aeda1dfd17ad3b6ccadc9b0/examples/protocols/sntp/main/sntp_example_main.c#L135-L136
Thank you, @david-cermak, so this seems to be intentionally. To prevent others from having issues, it would be nice to have some hint in the documentation.
would be nice to have some hint in the documentation.
sorry for the delay, documented directly in the IDF example
Thank you.
For a (sort of) clock I need to synchronize time on a regular basis. As the clock may be used in different WLANs, and not all internet providers allow access to public NTP servers, having a fixed ntp server (like
pool.ntp.org
) does not work. In these cases the NTP service has to be provided by the internet router. On the other hand, not all internet routers provide dhcp option 42. So, a mixed configuration is needed.The code thus far is (using esp-arduino):
But this does not set any fallback server. Digging deeper, in WiFi.begin() dhcp functionality is called, and from
dhcp.c
:In
sntp.c
I read:But the comment is not correct. "Initialize one of the NTP servers" does not reflect the function.
@param num
is not the index, but the number of ntp servers to be set from DHCP.@param server
is a pointer to an array of IP addresses. Now, the function works as follows:num
NTP server addresses from DHCPThe solution so far (at the moment) is to call
after the call to
WiFi.begin()
.Is there any possibility to force keeping already configured (static) ntp server addresses, e.g. remove the lines setting the servers to NULL in
dhcp_set_ntp_servers
, overwriting only address #0 ?