Skip to content

get NTP server from DHCP #2483

@tomtobback

Description

@tomtobback

Hi, i am trying to have my ESP32s receive an NTP server from DHCP on my OpenWRT router. I am testing this using the native time functions as in the ESP32>Time>SimpleTime example.
When i use the router's IP address as "ntpServer" i get the router's time as expected.
I understand that as part of DHCP, the router can also provide an NTP server address to the ESP32. LWIP seems to offer this feature, it is mentioned in https://github.com/espressif/arduino-esp32/blob/master/tools/sdk/include/lwip/lwip/opt.h line875:

/**
 * LWIP_DHCP_GETS_NTP==1: Request NTP servers with discover/select. For each
 * response packet, an callback is called, which has to be provided by the port:
 * void dhcp_set_ntp_servers(u8_t num_ntp_servers, ip_addr_t* ntp_server_addrs);
*/
#if !defined LWIP_DHCP_GET_NTP_SRV || defined __DOXYGEN__
#define LWIP_DHCP_GET_NTP_SRV           0
#endif

When i set this LWIP_DHCP_GET_NTP_SRV to 1 and compile, i expect it to work but it seems it does not ('failed to obtain time'). I have looked around for this function 'dhcp_set_ntp_servers' but cannot find it, except in https://github.com/espressif/arduino-esp32/blob/master/tools/sdk/include/lwip/lwip/dhcp.h

#if LWIP_DHCP_GET_NTP_SRV
/** This function must exist, in other to add offered NTP servers to
 * the NTP (or SNTP) engine.
 * See LWIP_DHCP_MAX_NTP_SERVERS */
extern void dhcp_set_ntp_servers(u8_t num_ntp_servers, const ip4_addr_t* ntp_server_addrs);
#endif /* LWIP_DHCP_GET_NTP_SRV */

But that does not seem to define the function.
[i am using the Arduino IDE]
Has anyone tried this, or any advice?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: StaleIssue is stale stage (outdated/stuck)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions