Skip to content

Commit

Permalink
Expand NTP-TZ-DST example to list SNTP servers (#6611)
Browse files Browse the repository at this point in the history
This change expands the NTP-TZ-DST example to list the active
SNTP servers. It lists the IP address server name (if used) and
reachability in ntpq style octal format.

Tests:
 - Build against all LwIP stack configurations and correct
   operation with a single SNTP server
 - Vary connectivity to an SNTP server and check reachability
   updates
 - Configure 3 SNTP servers by name
 - With a patched LwIP stack that supports simultaneous DHCP
   and DHCPv6 SNTP servers check that all server details are
   listed and update correctly during operation
  • Loading branch information
davefiddes authored and earlephilhower committed Oct 8, 2019
1 parent 8c3f1be commit d3debb6
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions libraries/esp8266/examples/NTP-TZ-DST/NTP-TZ-DST.ino
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,25 @@ void showTime() {
Serial.print("ctime: ");
Serial.print(ctime(&now));

#if LWIP_VERSION_MAJOR > 1
// LwIP v2 is able to list more details about the currently configured SNTP servers
for (int i = 0; i < SNTP_MAX_SERVERS; i++) {
IPAddress sntp = *sntp_getserver(i);
const char* name = sntp_getservername(i);
if (sntp.isSet()) {
Serial.printf("sntp%d: ", i);
if (name) {
Serial.printf("%s (%s) ", name, sntp.toString().c_str());
} else {
Serial.printf("%s ", sntp.toString().c_str());
}
Serial.printf("IPv6: %s Reachability: %o\n",
sntp.isV6() ? "Yes" : "No",
sntp_getreachability(i));
}
}
#endif

Serial.println();
}

Expand Down

0 comments on commit d3debb6

Please sign in to comment.