Skip to content

SNTP, Time, TZ, libc

M Hightower edited this page Sep 18, 2018 · 31 revisions

Time

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

TZ Variable

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.

DHCP and NTP Server - Observations

  • 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 to configTime() or sntp_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. When lwIP is built with the defines: LWIP_DHCP and SNTP_GET_SERVERS_FROM_DHCP set.
  • Calls to sntp_setserver(), when built with SNTP_SERVER_DNS defined, will set to NULL the NTP Server Name set by a previous call to sntp_setservername(). Note, this is how dhcp_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.
Clone this wiki locally