Return result of update() and forceUpdate()
This commit is contained in:
parent
8dfbf23463
commit
b0776ef19c
@ -60,7 +60,7 @@ void NTPClient::begin(int port) {
|
|||||||
this->_udpSetup = true;
|
this->_udpSetup = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NTPClient::forceUpdate() {
|
bool 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 @@ void NTPClient::forceUpdate() {
|
|||||||
do {
|
do {
|
||||||
delay ( 10 );
|
delay ( 10 );
|
||||||
cb = this->_udp->parsePacket();
|
cb = this->_udp->parsePacket();
|
||||||
if (timeout > 100) return; // timeout after 1000 ms
|
if (timeout > 100) return false; // timeout after 1000 ms
|
||||||
timeout++;
|
timeout++;
|
||||||
} while (cb == 0);
|
} while (cb == 0);
|
||||||
|
|
||||||
@ -88,14 +88,17 @@ void NTPClient::forceUpdate() {
|
|||||||
unsigned long secsSince1900 = highWord << 16 | lowWord;
|
unsigned long secsSince1900 = highWord << 16 | lowWord;
|
||||||
|
|
||||||
this->_currentEpoc = secsSince1900 - SEVENZYYEARS;
|
this->_currentEpoc = secsSince1900 - SEVENZYYEARS;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NTPClient::update() {
|
bool 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
|
||||||
this->forceUpdate();
|
return this->forceUpdate();
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long NTPClient::getRawTime() {
|
unsigned long NTPClient::getRawTime() {
|
||||||
|
@ -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
|
* 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.
|
* 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.
|
* This will force the update from the NTP Server.
|
||||||
|
*
|
||||||
|
* @return true on success, false on failure
|
||||||
*/
|
*/
|
||||||
void forceUpdate();
|
bool forceUpdate();
|
||||||
|
|
||||||
String getDay();
|
String getDay();
|
||||||
String getHours();
|
String getHours();
|
||||||
|
Loading…
Reference in New Issue
Block a user