Skip to content

Commit 419b39b

Browse files
committed
TimeService: make sure EPOCH_AT_COMPILE_TIME is not stored inside RTC
1 parent 14eff91 commit 419b39b

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/utility/time/TimeService.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,17 @@ unsigned long TimeServiceClass::getTime()
143143
sync();
144144
}
145145

146-
/* Read time from RTC */
147-
unsigned long utc = getRTC();
148-
return isTimeValid(utc) ? utc : EPOCH_AT_COMPILE_TIME;
146+
/* Use RTC time if has been configured at least once */
147+
if(_last_sync_tick) {
148+
return getRTC();
149+
}
150+
151+
/* Return the epoch timestamp at compile time as a last line of defense
152+
* trying to connect to the server. Otherwise the certificate expiration
153+
* date is wrong and we'll be unable to establish a connection. Schedulers
154+
* won't work correctly using this value.
155+
*/
156+
return EPOCH_AT_COMPILE_TIME;
149157
}
150158

151159
void TimeServiceClass::setTime(unsigned long time)
@@ -157,7 +165,7 @@ bool TimeServiceClass::sync()
157165
{
158166
_is_rtc_configured = false;
159167

160-
unsigned long utc = EPOCH_AT_COMPILE_TIME;
168+
unsigned long utc = EPOCH;
161169
if(_sync_func) {
162170
utc = _sync_func();
163171
} else {
@@ -308,12 +316,8 @@ unsigned long TimeServiceClass::getRemoteTime()
308316
}
309317
}
310318

311-
/* Return the epoch timestamp at compile time as a last
312-
* line of defense. Otherwise the certificate expiration
313-
* date is wrong and we'll be unable to establish a connection
314-
* to the server.
315-
*/
316-
return EPOCH_AT_COMPILE_TIME;
319+
/* Return known invalid value because we are not connected */
320+
return EPOCH;
317321
}
318322

319323
#endif /* HAS_TCP */

0 commit comments

Comments
 (0)