File tree 1 file changed +8
-1
lines changed
hardware/esp8266com/esp8266/libraries/ESP8266WiFi/examples/NTPClient
1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,11 @@ char pass[] = "********"; // your network password
27
27
28
28
unsigned int localPort = 2390 ; // local port to listen for UDP packets
29
29
30
- IPAddress timeServer (129 , 6 , 15 , 28 ); // time.nist.gov NTP server
30
+ /* Don't hardwire the IP address or we won't get the benefits of the pool.
31
+ * Lookup the IP address for the host name instead */
32
+ // IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server
33
+ IPAddress timeServerIP; // time.nist.gov NTP server address
34
+ const char * ntpServerName = " time.nist.gov" ;
31
35
32
36
const int NTP_PACKET_SIZE = 48 ; // NTP time stamp is in the first 48 bytes of the message
33
37
@@ -65,6 +69,9 @@ void setup()
65
69
66
70
void loop ()
67
71
{
72
+ // get a random server from the pool
73
+ WiFi.hostByName (ntpServerName, timeServerIP);
74
+
68
75
sendNTPpacket (timeServer); // send an NTP packet to a time server
69
76
// wait to see if a reply is available
70
77
delay (1000 );
You can’t perform that action at this time.
0 commit comments