@@ -105,10 +105,9 @@ TimeService::TimeService()
105105, _is_tz_configured(false )
106106, _timezone_offset(0 )
107107, _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 )
112111{
113112
114113}
@@ -130,7 +129,7 @@ unsigned long TimeService::getTime()
130129{
131130 /* Check if it's time to sync */
132131 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 ;
134133 if (!_is_rtc_configured || is_ntp_sync_timeout) {
135134 sync ();
136135 }
@@ -145,7 +144,6 @@ void TimeService::setTime(unsigned long time)
145144 setRTC (time);
146145}
147146
148- #ifdef HAS_TCP
149147bool TimeService::sync ()
150148{
151149 _is_rtc_configured = false ;
@@ -166,17 +164,23 @@ bool TimeService::sync()
166164 if (isTimeValid (utc)) {
167165 DEBUG_DEBUG (" TimeServiceClass::%s Drift: %d RTC value: %u" , __FUNCTION__, getRTC () - utc, utc);
168166 setRTC (utc);
169- _last_ntp_sync_tick = millis ();
167+ _last_sync_tick = millis ();
170168 _is_rtc_configured = true ;
171169 }
172170 return _is_rtc_configured;
173171}
174172
175173void TimeService::setSyncInterval (unsigned long seconds)
176174{
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+ }
178183}
179- #endif
180184
181185void TimeService::setTimeZoneData (long offset, unsigned long dst_until)
182186{
0 commit comments