Skip to content

Commit 4d37916

Browse files
committed
Return result of update() and forceUpdate()
1 parent 3c1d6b1 commit 4d37916

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

NTPClient.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ NTPClient::NTPClient(UDP& udp, const char* poolServerName, int timeOffset, int u
4848
this->_updateInterval = updateInterval;
4949
}
5050

51-
void NTPClient::forceUpdate() {
51+
bool NTPClient::forceUpdate() {
5252
#ifdef DEBUG_NTPClient
5353
Serial.println("Update from NTP Server");
5454
#endif
@@ -61,7 +61,7 @@ void NTPClient::forceUpdate() {
6161
do {
6262
delay ( 10 );
6363
cb = this->_udp->parsePacket();
64-
if (timeout > 100) return; // timeout after 1000 ms
64+
if (timeout > 100) return false; // timeout after 1000 ms
6565
timeout++;
6666
} while (cb == 0);
6767

@@ -78,12 +78,13 @@ void NTPClient::forceUpdate() {
7878
this->_currentEpoc = secsSince1900 - SEVENZYYEARS;
7979
}
8080

81-
void NTPClient::update() {
81+
bool NTPClient::update() {
8282
if ((millis() - this->_lastUpdate >= this->_updateInterval) // Update after _updateInterval
8383
|| this->_lastUpdate == 0) { // Update if there was no update yet.
8484
if (this->_lastUpdate == 0) this->_udp->begin(this->_port); // Start _udp if there was no update yet.
85-
this->forceUpdate();
85+
return this->forceUpdate();
8686
}
87+
return true;
8788
}
8889

8990
unsigned long NTPClient::getRawTime() {

NTPClient.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@ class NTPClient {
3434
/**
3535
* This should be called in the main loop of your application. By default an update from the NTP Server is only
3636
* made every 60 seconds. This can be configured in the NTPClient constructor.
37+
*
38+
* @return true on success, false on failure
3739
*/
38-
void update();
40+
bool update();
3941

4042
/**
4143
* This will force the update from the NTP Server.
44+
*
45+
* @return true on success, false on failure
4246
*/
43-
void forceUpdate();
47+
bool forceUpdate();
4448

4549
String getDay();
4650
String getHours();

0 commit comments

Comments
 (0)