File tree 2 files changed +6
-0
lines changed
2 files changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,8 @@ void NTPClient::begin(int port) {
56
56
this ->_port = port;
57
57
58
58
this ->_udp ->begin (this ->_port );
59
+
60
+ this ->_udpSetup = true ;
59
61
}
60
62
61
63
void NTPClient::forceUpdate () {
@@ -91,6 +93,7 @@ void NTPClient::forceUpdate() {
91
93
void NTPClient::update () {
92
94
if ((millis () - this ->_lastUpdate >= this ->_updateInterval ) // Update after _updateInterval
93
95
|| this ->_lastUpdate == 0 ) { // Update if there was no update yet.
96
+ if (!this ->_udpSetup ) this ->begin (); // setup the UDP client if needed
94
97
this ->forceUpdate ();
95
98
}
96
99
}
@@ -130,6 +133,8 @@ String NTPClient::getFormattedTime() {
130
133
131
134
void NTPClient::end () {
132
135
this ->_udp ->stop ();
136
+
137
+ this ->_udpSetup = false ;
133
138
}
134
139
135
140
void NTPClient::sendNTPPacket () {
Original file line number Diff line number Diff line change 11
11
class NTPClient {
12
12
private:
13
13
UDP* _udp;
14
+ bool _udpSetup = false ;
14
15
15
16
const char * _poolServerName = " time.nist.gov" ; // Default time server
16
17
int _port = NTP_DEFAULT_LOCAL_PORT;
You can’t perform that action at this time.
0 commit comments