Skip to content

Commit

Permalink
Improve time synch blocking loop
Browse files Browse the repository at this point in the history
  • Loading branch information
lbussy committed Mar 21, 2020
1 parent 2a36eee commit ede0118
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/ntp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,17 @@ void setClock() {
Log.notice(F("Entering blocking loop to get NTP time."));
blinker.attach_ms(NTPBLINK, ntpBlinker);
configTime(GMT, 0, "pool.ntp.org", "time.nist.gov");
time_t nowSecs;
time_t nowSecs = time(nullptr);
time_t startSecs = time(nullptr);
while (nowSecs < EPOCH_1_1_2019) {
if (nowSecs - startSecs > 10) {
#ifdef LOG_LEVEL
Serial.println();
#endif
Log.verbose(F("Re-requesting time hack." CR));
configTime(GMT, 0, "pool.ntp.org", "time.nist.gov");
startSecs = time(nullptr);
}
#ifdef LOG_LEVEL
Serial.print(F("."));
#endif
Expand All @@ -40,7 +49,7 @@ void setClock() {
#ifdef LOG_LEVEL
Serial.println();
#endif
Log.notice(F("NTP time set."));
Log.notice(F("NTP time set." CR));
struct tm timeinfo;
gmtime_r(&nowSecs, &timeinfo);
}
Expand Down

0 comments on commit ede0118

Please sign in to comment.