@@ -105,10 +105,9 @@ TimeService::TimeService()
105
105
, _is_tz_configured(false )
106
106
, _timezone_offset(0 )
107
107
, _timezone_dst_until(0 )
108
- #ifdef HAS_TCP
109
- , _last_ntp_sync_tick(0 )
110
- , _ntp_sync_interval_ms(TIMESERVICE_NTP_SYNC_TIMEOUT_ms)
111
- #endif
108
+ , _last_sync_tick(0 )
109
+ , _sync_interval_ms(TIMESERVICE_NTP_SYNC_TIMEOUT_ms)
110
+ , _sync_func(nullptr )
112
111
{
113
112
114
113
}
@@ -130,7 +129,7 @@ unsigned long TimeService::getTime()
130
129
{
131
130
/* Check if it's time to sync */
132
131
unsigned long const current_tick = millis ();
133
- bool const is_ntp_sync_timeout = (current_tick - _last_ntp_sync_tick ) > _ntp_sync_interval_ms ;
132
+ bool const is_ntp_sync_timeout = (current_tick - _last_sync_tick ) > _sync_interval_ms ;
134
133
if (!_is_rtc_configured || is_ntp_sync_timeout) {
135
134
sync ();
136
135
}
@@ -145,7 +144,6 @@ void TimeService::setTime(unsigned long time)
145
144
setRTC (time );
146
145
}
147
146
148
- #ifdef HAS_TCP
149
147
bool TimeService::sync ()
150
148
{
151
149
_is_rtc_configured = false ;
@@ -166,17 +164,23 @@ bool TimeService::sync()
166
164
if (isTimeValid (utc)) {
167
165
DEBUG_DEBUG (" TimeServiceClass::%s Drift: %d RTC value: %u" , __FUNCTION__, getRTC () - utc, utc);
168
166
setRTC (utc);
169
- _last_ntp_sync_tick = millis ();
167
+ _last_sync_tick = millis ();
170
168
_is_rtc_configured = true ;
171
169
}
172
170
return _is_rtc_configured;
173
171
}
174
172
175
173
void TimeService::setSyncInterval (unsigned long seconds)
176
174
{
177
- _ntp_sync_interval_ms = seconds * 1000 ;
175
+ _sync_interval_ms = seconds * 1000 ;
176
+ }
177
+
178
+ void TimeService::setSyncFunction (syncTimeFunctionPtr sync_func)
179
+ {
180
+ if (sync_func) {
181
+ _sync_func = sync_func;
182
+ }
178
183
}
179
- #endif
180
184
181
185
void TimeService::setTimeZoneData (long offset, unsigned long dst_until)
182
186
{
0 commit comments