1
- /* *
1
+ /* *
2
2
* The MIT License (MIT)
3
3
* Copyright (c) 2015 by Fabrice Weinberg
4
- *
4
+ *
5
5
* Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
* of this software and associated documentation files (the "Software"), to deal
7
7
* in the Software without restriction, including without limitation the rights
@@ -50,14 +50,14 @@ void NTPClient::begin() {
50
50
this ->forceUpdate ();
51
51
}
52
52
53
- void NTPClient::forceUpdate () {
53
+ void NTPClient::forceUpdate () {
54
54
#ifdef DEBUG_NTPClient
55
55
Serial.println (" Update from NTP Server" );
56
56
#endif
57
-
57
+
58
58
IPAddress address;
59
59
WiFi.hostByName (this ->_poolServerName , address);
60
-
60
+
61
61
this ->sendNTPPacket (address);
62
62
63
63
// Wait till data is there or timeout...
@@ -69,23 +69,23 @@ void NTPClient::forceUpdate() {
69
69
if (timeout > 100 ) return ; // timeout after 1000 ms
70
70
timeout++;
71
71
} while (cb == 0 );
72
-
73
- this ->_lastUpdate = millis () - (10 * (timeout + 1 )); // Account for delay in reading the time
74
-
72
+
73
+ this ->_lastUpdate = millis () - (10 * (timeout + 1 )); // Account for delay in reading the time
74
+
75
75
this ->_udp .read (this ->_packetBuffer , NTP_PACKET_SIZE);
76
76
77
77
unsigned long highWord = word (this ->_packetBuffer [40 ], this ->_packetBuffer [41 ]);
78
78
unsigned long lowWord = word (this ->_packetBuffer [42 ], this ->_packetBuffer [43 ]);
79
79
// combine the four bytes (two words) into a long integer
80
80
// this is NTP time (seconds since Jan 1 1900):
81
81
unsigned long secsSince1900 = highWord << 16 | lowWord;
82
-
82
+
83
83
this ->_currentEpoc = secsSince1900 - SEVENZYYEARS;
84
84
}
85
85
86
86
void NTPClient::update () {
87
87
unsigned long runtime = millis ();
88
- if (runtime - this ->_lastUpdate >= this ->_updateInterval && this ->_updateInterval != 0 ) {
88
+ if (runtime - this ->_lastUpdate >= this ->_updateInterval && this ->_updateInterval != 0 ) {
89
89
this ->forceUpdate ();
90
90
}
91
91
}
@@ -111,10 +111,10 @@ String NTPClient::getFormattedTime() {
111
111
unsigned long rawTime = this ->getRawTime ();
112
112
unsigned long hours = (rawTime % 86400L ) / 3600 ;
113
113
String hoursStr = hours < 10 ? " 0" + String (hours) : String (hours);
114
-
114
+
115
115
unsigned long minutes = (rawTime % 3600 ) / 60 ;
116
116
String minuteStr = minutes < 10 ? " 0" + String (minutes) : String (minutes);
117
-
117
+
118
118
unsigned long seconds = rawTime % 60 ;
119
119
String secondStr = seconds < 10 ? " 0" + String (seconds) : String (seconds);
120
120
0 commit comments