-
Notifications
You must be signed in to change notification settings - Fork 0
SNTP, Time, TZ, libc
M Hightower edited this page Sep 18, 2018
·
31 revisions
With the Arduino ESP8266 Core version number 2.4.0, the newlib C Library (libc) was added. And thus support for a familiar collection of time functions has been added. A manual for the newlib C Library can be found here
For libc to handle timezone and daylight savings time for a local, the TZ environment variable must be set. A description of the format can be found here on page 289 and here.
Also when calling configTime()
, use 0 for timezone and daylight options. This causes the sntp code to maintain a GMT zone time. The libc time function calls works off GMT zone time.
- The char strings pointers used to identify NTP Servers in the call to
configTime()
cannot be ephemeral. - A call to
dhcp_set_ntp_servers()
will overwrite any NTP Server Names set by a previous call toconfigTime()
orsntp_setservername()
. - When
dhcp_set_ntp_servers()
is called with a list of NTP Server Addresses, any remaining possitions, not set from the list, are cleared. -
dhcp_set_ntp_servers()
is called as part of the DHCP process. WhenlwIP
is built with the defines:LWIP_DHCP
andSNTP_GET_SERVERS_FROM_DHCP
set. - Calls to
sntp_setserver()
, when built withSNTP_SERVER_DNS
defined, will set toNULL
the NTP Server Name set by a previous call tosntp_setservername()
. Note, this is howdhcp_set_ntp_servers()
is clearing previously set NTP Server Names. - In summary, when the DHCP server has been configured to give out NTP Server Names,
calling
configTime()
with one to three NTP Server Name arguments has no effect. You just as well be calling with nullptr,configTime(0, 0, nullptr, nullptr, nullptr)
. - When the DHCP server has not been configured to give out NTP Server Name, then the NTP Server Names provided by configTime() are used.
- This information is my interpited of the code at
tools\sdk\lwip2\builder\lwip2-src\src\apps\sntp\sntp.c
.