11/* ***************************************************************************************************************************
22 UdpNTPClient.ino - Simple Arduino web server sample for ESP8266 AT-command shield
3-
3+
44 For Ethernet shields using ESP32_ENC (ESP32 + ENC28J60)
55
66 WebServer_ESP32_ENC is a library for the ESP32 with Ethernet ENC28J60 to run WebServer
@@ -81,7 +81,7 @@ char timeServer[] = "time.nist.gov"; // NTP server
8181unsigned int localPort = 2390 ; // local port to listen for UDP packets
8282
8383const int NTP_PACKET_SIZE = 48 ; // NTP timestamp is in the first 48 bytes of the message
84- const int UDP_TIMEOUT = 2000 ; // timeout in miliseconds to wait for an UDP packet to arrive
84+ const int UDP_TIMEOUT = 2000 ; // timeout in milliseconds to wait for an UDP packet to arrive
8585
8686byte packetBuffer[NTP_PACKET_SIZE]; // buffer to hold incoming and outgoing packets
8787
@@ -118,7 +118,6 @@ void sendNTPpacket(char *ntpSrv)
118118void setup ()
119119{
120120 Serial.begin (115200 );
121-
122121 while (!Serial && (millis () < 5000 ));
123122
124123 Serial.print (F (" \n Start UdpNTPClient on " ));
@@ -157,17 +156,16 @@ void setup()
157156 ESP32_ENC_waitForConnect ();
158157
159158 // /////////////////////////////////
160-
159+
161160 Udp.begin (localPort);
162161}
163162
164163void loop ()
165164{
166165 sendNTPpacket (timeServer); // send an NTP packet to a time server
167166
168- // wait for a reply for UDP_TIMEOUT miliseconds
167+ // wait for a reply for UDP_TIMEOUT milliseconds
169168 unsigned long startMs = millis ();
170-
171169 while (!Udp.available () && (millis () - startMs) < UDP_TIMEOUT) {}
172170
173171 // if there's data available, read a packet
@@ -195,7 +193,7 @@ void loop()
195193 // combine the four bytes (two words) into a long integer
196194 // this is NTP time (seconds since Jan 1 1900):
197195 unsigned long secsSince1900 = highWord << 16 | lowWord;
198-
196+
199197 Serial.print (F (" Seconds since Jan 1 1900 = " ));
200198 Serial.println (secsSince1900);
201199
@@ -212,25 +210,25 @@ void loop()
212210 Serial.print (F (" The UTC time is " )); // UTC is the time at Greenwich Meridian (GMT)
213211 Serial.print ((epoch % 86400L ) / 3600 ); // print the hour (86400 equals secs per day)
214212 Serial.print (F (" :" ));
215-
216- if (((epoch % 3600 ) / 60 ) < 10 )
213+
214+ if (((epoch % 3600 ) / 60 ) < 10 )
217215 {
218216 // In the first 10 minutes of each hour, we'll want a leading '0'
219217 Serial.print (F (" 0" ));
220218 }
221-
219+
222220 Serial.print ((epoch % 3600 ) / 60 ); // print the minute (3600 equals secs per minute)
223221 Serial.print (F (" :" ));
224-
225- if ((epoch % 60 ) < 10 )
222+
223+ if ((epoch % 60 ) < 10 )
226224 {
227225 // In the first 10 seconds of each minute, we'll want a leading '0'
228226 Serial.print (F (" 0" ));
229227 }
230-
228+
231229 Serial.println (epoch % 60 ); // print the second
232230 }
233-
231+
234232 // wait ten seconds before asking for the time again
235233 delay (10000 );
236234}
0 commit comments