Skip to content

Commit 7cd0f63

Browse files
committed
Config RTC for LoRa devices using EPOCH_AT_COMPILE_TIME
1 parent 56de2c1 commit 7cd0f63

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/utility/time/TimeService.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,13 @@ void TimeService::begin(ConnectionHandler * con_hdl)
121121
{
122122
_con_hdl = con_hdl;
123123
initRTC();
124+
#ifdef HAS_LORA
125+
setRTC(EPOCH_AT_COMPILE_TIME);
126+
#endif
124127
}
125128

126129
unsigned long TimeService::getTime()
127130
{
128-
#ifdef HAS_TCP
129131
/* Check if it's time to sync */
130132
unsigned long const current_tick = millis();
131133
bool const is_ntp_sync_timeout = (current_tick - _last_ntp_sync_tick) > _ntp_sync_interval_ms;
@@ -136,16 +138,25 @@ unsigned long TimeService::getTime()
136138
/* Read time from RTC */
137139
unsigned long utc = getRTC();
138140
return isTimeValid(utc) ? utc : EPOCH_AT_COMPILE_TIME;
139-
#else
140-
return EPOCH_AT_COMPILE_TIME;
141-
#endif
142141
}
143142

144143
#ifdef HAS_TCP
145144
bool TimeService::sync()
146145
{
147146
_is_rtc_configured = false;
148-
unsigned long utc = getRemoteTime();
147+
148+
unsigned long utc = EPOCH_AT_COMPILE_TIME;
149+
if(_sync_func) {
150+
utc = _sync_func();
151+
} else {
152+
#ifdef HAS_TCP
153+
utc = getRemoteTime();
154+
#endif
155+
#ifdef HAS_LORA
156+
/* Just keep incrementing stored RTC value*/
157+
utc = getRTC();
158+
#endif
159+
}
149160

150161
if(isTimeValid(utc)) {
151162
DEBUG_DEBUG("TimeServiceClass::%s Drift: %d RTC value: %u", __FUNCTION__, getRTC() - utc, utc);

0 commit comments

Comments
 (0)