Skip to content

Return result of update() and forceUpdate() #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions NTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand All @@ -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() {
Expand Down
8 changes: 6 additions & 2 deletions NTPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down