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:
parent
9db67ec7b0
commit
72ab7cd41c
@ -27,7 +27,11 @@ char pass[] = "********"; // your network password
|
|||||||
|
|
||||||
unsigned int localPort = 2390; // local port to listen for UDP packets
|
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
|
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()
|
void loop()
|
||||||
{
|
{
|
||||||
|
//get a random server from the pool
|
||||||
|
WiFi.hostByName(ntpServerName, timeServerIP);
|
||||||
|
|
||||||
sendNTPpacket(timeServer); // send an NTP packet to a time server
|
sendNTPpacket(timeServer); // send an NTP packet to a time server
|
||||||
// wait to see if a reply is available
|
// wait to see if a reply is available
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user