khoih-prog / ESPAsync_WiFiManager

This is an ESP32 (including ESP32-S2 and ESP32-C3) / ESP8266 WiFi Connection Manager, using ESPAsyncWebServer, with fallback web configuration portal. Use this library for configuring ESP32, ESP8266 modules' WiFi, etc. Credentials at runtime. You can also specify static DNS servers, personalized HostName, fixed or random AP WiFi channel. With examples supporting ArduinoJson 6.0.0+ as well as 5.13.5- . Using AsyncDNSServer instead of DNSServer now.
MIT License
290 stars 73 forks source link

Use NTP server given by DHCP server option 42 #65

Closed fow0ryl closed 2 years ago

fow0ryl commented 2 years ago

I would like to use the ntp server address given by a local dhcp server. If the DHCP server is configured with option 42 all devices in the LAN/VLAN can use that address. No problems with changing addresses of local ntp-servers or blocking firewalls anymore ...

Henning

khoih-prog commented 2 years ago

Have a look at this Tips on using NTP-Services #63

fow0ryl commented 2 years ago

Sorry for your inconvenience. I have read #63 but I think that it did not address my problem. In #63 the ntp server is on the local router/gateway. But if the ntp-server is located on another device in the local network it is not possible to use the routers address for ntp requests. Thats why the correct ntp server address is set as dhcp option 42 ...

khoih-prog commented 2 years ago

As long as you know the IP of that NTP server in your local network and it's reachable, you can either hardcode its IP or save it in Dynamic Parameters List to use whenever necessary. This is why the Dynamic Parameters feature is designed for.

This can do by you and this library certainly can not provide the ready-made solution for every use cases.

Have a look at ESP_WiFiManager_Lite Library or its twin ESPAsync_WiFiManager_Lite Library for easier way to deal with Dynamic Parameters

khoih-prog commented 2 years ago

If you have assigned your local NTP server a hostname, such as My_NTP_Server, then you can use that name instead of "time.nist.gov" or "0.pool.ntp.org", and if your local router DHCP is working OK, you can just use that name and hopefully the local NTP address will be resolved correctly as this really depends on the router / GW you're using.

For ESP, hopefully you can use mDNS to resolve NTP-server IP address from local hostname via Bonjour service. Check MDNS_Generic Library

Another way to use is DDNS + UPnP. Check UPnP_Generic Library. TO use this option, you must have DDNS address, such as domain name acquired from duckdns, ddns, NoIP, etc.

Certainly, this is slower and not as independent as the other option of using the Dynamic Parameters after you've known the IP address of your local NTP.