1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

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.
This commit is contained in:
moeur 2015-05-26 07:55:56 -07:00
parent 9db67ec7b0
commit 72ab7cd41c

View File

@ -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);