Skip to content

Commit d3debb6

Browse files
davefiddesearlephilhower
authored andcommitted
Expand NTP-TZ-DST example to list SNTP servers (#6611)
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
1 parent 8c3f1be commit d3debb6

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

libraries/esp8266/examples/NTP-TZ-DST/NTP-TZ-DST.ino

+19
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,25 @@ void showTime() {
130130
Serial.print("ctime: ");
131131
Serial.print(ctime(&now));
132132

133+
#if LWIP_VERSION_MAJOR > 1
134+
// LwIP v2 is able to list more details about the currently configured SNTP servers
135+
for (int i = 0; i < SNTP_MAX_SERVERS; i++) {
136+
IPAddress sntp = *sntp_getserver(i);
137+
const char* name = sntp_getservername(i);
138+
if (sntp.isSet()) {
139+
Serial.printf("sntp%d: ", i);
140+
if (name) {
141+
Serial.printf("%s (%s) ", name, sntp.toString().c_str());
142+
} else {
143+
Serial.printf("%s ", sntp.toString().c_str());
144+
}
145+
Serial.printf("IPv6: %s Reachability: %o\n",
146+
sntp.isV6() ? "Yes" : "No",
147+
sntp_getreachability(i));
148+
}
149+
}
150+
#endif
151+
133152
Serial.println();
134153
}
135154

0 commit comments

Comments
 (0)