diff --git a/NTPClient.cpp b/NTPClient.cpp index 82207ba..58bc539 100755 --- a/NTPClient.cpp +++ b/NTPClient.cpp @@ -98,11 +98,15 @@ bool NTPClient::forceUpdate() { do { delay ( 10 ); cb = this->_udp->parsePacket(); - if (timeout > 100) return false; // timeout after 1000 ms + if (timeout > 100) { + this->_lastUpdateOk = false; + return false; // timeout after 1000 ms + } timeout++; } while (cb == 0); this->_lastUpdate = millis() - (10 * (timeout + 1)); // Account for delay in reading the time + this->_lastUpdateOk = true; this->_udp->read(this->_packetBuffer, NTP_PACKET_SIZE); @@ -123,7 +127,7 @@ bool NTPClient::update() { if (!this->_udpSetup || this->_port != NTP_DEFAULT_LOCAL_PORT) this->begin(this->_port); // setup the UDP client if needed return this->forceUpdate(); } - return false; // return false if update does not occur + return this->_lastUpdateOk; // return last sync state } unsigned long NTPClient::getEpochTime() const { diff --git a/NTPClient.h b/NTPClient.h index bc325d3..8e8a591 100755 --- a/NTPClient.h +++ b/NTPClient.h @@ -22,6 +22,7 @@ class NTPClient { unsigned long _currentEpoc = 0; // In s unsigned long _lastUpdate = 0; // In ms + bool _lastUpdateOk = false; // byte _packetBuffer[NTP_PACKET_SIZE];