Return result of update() and forceUpdate()

This commit is contained in:
Sandeep Mistry 2016-04-12 15:30:40 -04:00
parent 8dfbf23463
commit b0776ef19c
2 changed files with 13 additions and 6 deletions

View File

@ -60,7 +60,7 @@ void NTPClient::begin(int port) {
this->_udpSetup = true;
}
void NTPClient::forceUpdate() {
bool NTPClient::forceUpdate() {
#ifdef DEBUG_NTPClient
Serial.println("Update from NTP Server");
#endif
@ -73,7 +73,7 @@ void NTPClient::forceUpdate() {
do {
delay ( 10 );
cb = this->_udp->parsePacket();
if (timeout > 100) return; // timeout after 1000 ms
if (timeout > 100) return false; // timeout after 1000 ms
timeout++;
} while (cb == 0);
@ -88,14 +88,17 @@ void NTPClient::forceUpdate() {
unsigned long secsSince1900 = highWord << 16 | lowWord;
this->_currentEpoc = secsSince1900 - SEVENZYYEARS;
return true;
}
void NTPClient::update() {
bool NTPClient::update() {
if ((millis() - this->_lastUpdate >= this->_updateInterval) // Update after _updateInterval
|| this->_lastUpdate == 0) { // Update if there was no update yet.
if (!this->_udpSetup) this->begin(); // setup the UDP client if needed
this->forceUpdate();
return this->forceUpdate();
}
return true;
}
unsigned long NTPClient::getRawTime() {

View File

@ -46,13 +46,17 @@ class NTPClient {
/**
* This should be called in the main loop of your application. By default an update from the NTP Server is only
* made every 60 seconds. This can be configured in the NTPClient constructor.
*
* @return true on success, false on failure
*/
void update();
bool update();
/**
* This will force the update from the NTP Server.
*
* @return true on success, false on failure
*/
void forceUpdate();
bool forceUpdate();
String getDay();
String getHours();