File tree Expand file tree Collapse file tree 2 files changed +6
-0
lines changed
Expand file tree Collapse file tree 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) {
5656 this ->_port = port;
5757
5858 this ->_udp ->begin (this ->_port );
59+
60+ this ->_udpSetup = true ;
5961}
6062
6163void NTPClient::forceUpdate () {
@@ -91,6 +93,7 @@ void NTPClient::forceUpdate() {
9193void NTPClient::update () {
9294 if ((millis () - this ->_lastUpdate >= this ->_updateInterval ) // Update after _updateInterval
9395 || this ->_lastUpdate == 0 ) { // Update if there was no update yet.
96+ if (!this ->_udpSetup ) this ->begin (); // setup the UDP client if needed
9497 this ->forceUpdate ();
9598 }
9699}
@@ -130,6 +133,8 @@ String NTPClient::getFormattedTime() {
130133
131134void NTPClient::end () {
132135 this ->_udp ->stop ();
136+
137+ this ->_udpSetup = false ;
133138}
134139
135140void NTPClient::sendNTPPacket () {
Original file line number Diff line number Diff line change 1111class NTPClient {
1212 private:
1313 UDP* _udp;
14+ bool _udpSetup = false ;
1415
1516 const char * _poolServerName = " time.nist.gov" ; // Default time server
1617 int _port = NTP_DEFAULT_LOCAL_PORT;
You can’t perform that action at this time.
0 commit comments