File tree 1 file changed +48
-0
lines changed
1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < WiFi.h>
2
+ #include < WiFiUdp.h>
3
+
4
+ #include " NTPClient.h"
5
+
6
+ #define SSID " <your-ssid>"
7
+ #define PASSWORD " <your-password>"
8
+
9
+ WiFiUDP ntpUDP;
10
+ NTPClient timeClient (ntpUDP, " 0.asia.pool.ntp.org" , 0 , 1500 );
11
+
12
+ void setup (){
13
+ Serial.begin (115200 );
14
+
15
+ WiFi.begin (SSID, PASSWORD);
16
+
17
+ while ( WiFi.status () != WL_CONNECTED ) {
18
+ delay ( 500 );
19
+ Serial.print ( " ." );
20
+ }
21
+
22
+ timeClient.begin ();
23
+ }
24
+
25
+ void loop () {
26
+ long int loopMillis = millis ();
27
+ static int prevRes = 0 ;
28
+ // with update() method loop will be blocked until time is updated
29
+ // timeClient.update();
30
+ int res = timeClient.asyncUpdate ();
31
+
32
+ if (res != prevRes) {
33
+ Serial.printf (" Result: %d\n " , res);
34
+ prevRes = res;
35
+ }
36
+
37
+ static long int lm = 0 ;
38
+
39
+ if (millis () - lm > 1000 ) {
40
+ lm = millis ();
41
+ Serial.printf (" %s.%d\n " , timeClient.getFormattedTime ().c_str (), int (timeClient.getEpochTimeMillis ()%1000 ));
42
+ }
43
+
44
+ long int dd = millis () - loopMillis;
45
+ if (dd > 10 ) {
46
+ Serial.printf (" Loop took %d ms...\n " , dd);
47
+ }
48
+ }
You can’t perform that action at this time.
0 commit comments