Modified update(), forceUpdate() to return integer

This commit is contained in:
bitsy 2019-09-17 10:14:28 -07:00 committed by GitHub
parent 712c58c18e
commit 735ccffcc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,7 +60,7 @@ void NTPClient::begin(int port) {
this->_udpSetup = true; this->_udpSetup = true;
} }
bool NTPClient::forceUpdate() { uint8_t NTPClient::forceUpdate() {
#ifdef DEBUG_NTPClient #ifdef DEBUG_NTPClient
Serial.println("Update from NTP Server"); Serial.println("Update from NTP Server");
#endif #endif
@ -73,7 +73,7 @@ bool NTPClient::forceUpdate() {
do { do {
delay ( 10 ); delay ( 10 );
cb = this->_udp->parsePacket(); cb = this->_udp->parsePacket();
if (timeout > 100) return false; // timeout after 1000 ms if (timeout > 100) return 0; // timeout after 1000 ms; return 0 if update fails
timeout++; timeout++;
} while (cb == 0); } while (cb == 0);
@ -89,16 +89,16 @@ bool NTPClient::forceUpdate() {
this->_currentEpoc = secsSince1900 - SEVENZYYEARS; this->_currentEpoc = secsSince1900 - SEVENZYYEARS;
return true; // return true after successful update return 2; // return 2 if update occurs successfully
} }
bool NTPClient::update() { uint8_t NTPClient::update() {
if ((millis() - this->_lastUpdate >= this->_updateInterval) // Update after _updateInterval if ((millis() - this->_lastUpdate >= this->_updateInterval) // Update after _updateInterval
|| this->_lastUpdate == 0) { // Update if there was no update yet. || this->_lastUpdate == 0) { // Update if there was no update yet.
if (!this->_udpSetup) this->begin(); // setup the UDP client if needed if (!this->_udpSetup) this->begin(); // setup the UDP client if needed
return this->forceUpdate(); return this->forceUpdate();
} }
return false; // return false if update does not occur return 1; // return 1 if update does not occur
} }
unsigned long NTPClient::getEpochTime() const { unsigned long NTPClient::getEpochTime() const {