diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index 3393df5bc5..6db94bc5fc 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -837,7 +837,7 @@ menu "LWIP" menu "SNTP" - config LWIP_DHCP_MAX_NTP_SERVERS + config LWIP_SNTP_MAX_SERVERS int "Maximum number of NTP servers" default 1 range 1 16 @@ -846,6 +846,23 @@ menu "LWIP" First argument of sntp_setserver/sntp_setservername functions is limited to this value. + config LWIP_DHCP_GET_NTP_SRV + bool "Request NTP servers from DHCP" + default n + help + If enabled, LWIP will add 'NTP' to Parameter-Request Option sent via DHCP-request. + DHCP server might reply with an NTP server address in option 42. + SNTP callback for such replies should be set accordingly (see sntp_servermode_dhcp() func.) + + config LWIP_DHCP_MAX_NTP_SERVERS + int "Maximum number of NTP servers aquired via DHCP" + default 1 + range 1 16 + depends on LWIP_DHCP_GET_NTP_SRV + help + Set maximum number of NTP servers aquired via DHCP-offer. + Should be less or equal to "Maximum number of NTP servers", any extra servers would be just ignored. + config LWIP_SNTP_UPDATE_DELAY int "Request interval to update time (ms)" range 15000 4294967295 @@ -1025,4 +1042,9 @@ menu "LWIP" depends on LWIP_DEBUG default n + config LWIP_SNTP_DEBUG + bool "Enable SNTP debug messages" + depends on LWIP_DEBUG + default n + endmenu diff --git a/components/lwip/port/esp32/include/lwipopts.h b/components/lwip/port/esp32/include/lwipopts.h index beeeae4169..c39268aa49 100644 --- a/components/lwip/port/esp32/include/lwipopts.h +++ b/components/lwip/port/esp32/include/lwipopts.h @@ -909,6 +909,15 @@ #define TCP_DEBUG LWIP_DBG_OFF #endif +/** + * SNTP_DEBUG: Enable debugging for SNTP. + */ +#ifdef CONFIG_LWIP_SNTP_DEBUG +#define SNTP_DEBUG LWIP_DBG_ON +#else +#define SNTP_DEBUG LWIP_DBG_OFF +#endif + /** * MEMP_DEBUG: Enable debugging in memp.c. */ @@ -1053,9 +1062,15 @@ ------------ SNTP options ------------ -------------------------------------- */ -/* - * SNTP update delay - in milliseconds - */ + +// Max number of SNTP servers handled (default equal to LWIP_DHCP_MAX_NTP_SERVERS) +#if defined CONFIG_LWIP_SNTP_MAX_SERVERS +#define SNTP_MAX_SERVERS CONFIG_LWIP_SNTP_MAX_SERVERS +#endif // CONFIG_LWIP_SNTP_MAX_SERVERS + +#ifdef CONFIG_LWIP_DHCP_GET_NTP_SRV +#define LWIP_DHCP_GET_NTP_SRV CONFIG_LWIP_DHCP_GET_NTP_SRV +#endif // CONFIG_LWIP_DHCP_GET_NTP_SRV /** Set this to 1 to support DNS names (or IP address strings) to set sntp servers * One server address/name can be defined as default if SNTP_SERVER_DNS == 1: diff --git a/examples/protocols/sntp/main/sntp_example_main.c b/examples/protocols/sntp/main/sntp_example_main.c index e0e910ce0d..3733241640 100644 --- a/examples/protocols/sntp/main/sntp_example_main.c +++ b/examples/protocols/sntp/main/sntp_example_main.c @@ -122,6 +122,14 @@ static void obtain_time(void) ESP_ERROR_CHECK(esp_netif_init()); ESP_ERROR_CHECK( esp_event_loop_create_default() ); + /** + * NTP server address could be aquired via DHCP, + * see LWIP_DHCP_GET_NTP_SRV menuconfig option + */ +#ifdef LWIP_DHCP_GET_NTP_SRV + sntp_servermode_dhcp(1); +#endif + /* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig. * Read "Establishing Wi-Fi or Ethernet Connection" section in * examples/protocols/README.md for more information about this function.