From 72ab7cd41cdf64013351daa409ce939d4d2bad08 Mon Sep 17 00:00:00 2001 From: moeur Date: Tue, 26 May 2015 07:55:56 -0700 Subject: [PATCH] Update NTPClient.ino Instead of hardwiring the IP address of one server into the program, look-up an IP address from the host name. This way you get a random server from the pool each time. --- libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino b/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino index 4a9771b5f..a3fdaf49c 100644 --- a/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino +++ b/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino @@ -27,7 +27,11 @@ char pass[] = "********"; // your network password unsigned int localPort = 2390; // local port to listen for UDP packets -IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server +/* Don't hardwire the IP address or we won't get the benefits of the pool. + * Lookup the IP address for the host name instead */ +//IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server +IPAddress timeServerIP; // time.nist.gov NTP server address +const char* ntpServerName = "time.nist.gov"; const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message @@ -65,6 +69,9 @@ void setup() void loop() { + //get a random server from the pool + WiFi.hostByName(ntpServerName, timeServerIP); + sendNTPpacket(timeServer); // send an NTP packet to a time server // wait to see if a reply is available delay(1000);