Merge branch 'feature/lwip_sntp_max_servers' into 'master'

lw-ip: Add config option for sntp max servers (GitHub PR)

Closes IDFGH-5616

See merge request espressif/esp-idf!14590
This commit is contained in:
David Čermák 2021-08-25 08:10:21 +00:00
commit 2417b9361f
3 changed files with 49 additions and 4 deletions

View File

@ -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

View File

@ -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:

View File

@ -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.