mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-07 14:44:32 +02:00
lwip: menuconfig option to enable ntp servers option request via DHCP
This could be toggled on/off, off is the default. SNTP debug option. Example update for ntp via DHCP Signed-off-by: Emil Muratov <gpm@hotplug.ru>
This commit is contained in:
@@ -846,13 +846,22 @@ 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.
|
||||
Must be less or equal to total "Maximum number of NTP servers".
|
||||
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)"
|
||||
@@ -1033,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
|
||||
|
@@ -910,6 +910,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.
|
||||
*/
|
||||
@@ -1075,9 +1084,13 @@ LWIP_FORWARD_DECLARE_C_CXX void sntp_sync_time(struct timeval *tv);
|
||||
LWIP_FORWARD_DECLARE_C_CXX uint32_t sntp_get_sync_interval(void);
|
||||
|
||||
// Max number of SNTP servers handled (default equal to LWIP_DHCP_MAX_NTP_SERVERS)
|
||||
#if CONFIG_LWIP_SNTP_MAX_SERVERS_DEFINED && !defined SNTP_MAX_SERVERS
|
||||
#if defined CONFIG_LWIP_SNTP_MAX_SERVERS
|
||||
#define SNTP_MAX_SERVERS CONFIG_LWIP_SNTP_MAX_SERVERS
|
||||
#endif // CONFIG_LWIP_SNTP_MAX_SERVERS_DEFINED
|
||||
#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:
|
||||
|
@@ -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.
|
||||
|
Reference in New Issue
Block a user