2424#include < time.h>
2525#include " TimeService.h"
2626#include " NTPUtils.h"
27+ #include " AIoTC_Const.h"
2728
2829#ifdef ARDUINO_ARCH_SAMD
2930 #include < RTCZero.h>
@@ -90,8 +91,7 @@ unsigned long esp8266_getRTC();
9091 **************************************************************************************/
9192
9293/* Default NTP synch is scheduled each 24 hours from startup */
93- static unsigned long const AIOT_TIMESERVICE_NTP_SYNC_TIMEOUT_ms = 86400000 ;
94-
94+ static time_t const TIMESERVICE_NTP_SYNC_TIMEOUT_ms = DAYS * 1000 ;
9595static time_t const EPOCH_AT_COMPILE_TIME = cvt_time(__DATE__);
9696static time_t const EPOCH = 0 ;
9797
@@ -106,6 +106,7 @@ TimeService::TimeService()
106106, _timezone_offset(0 )
107107, _timezone_dst_until(0 )
108108, _last_ntp_sync_tick(0 )
109+ , _ntp_sync_interval_ms(TIMESERVICE_NTP_SYNC_TIMEOUT_ms)
109110{
110111
111112}
@@ -124,7 +125,7 @@ unsigned long TimeService::getTime()
124125{
125126 /* Check if it's time to sync */
126127 unsigned long const current_tick = millis ();
127- bool const is_ntp_sync_timeout = (current_tick - _last_ntp_sync_tick) > AIOT_TIMESERVICE_NTP_SYNC_TIMEOUT_ms ;
128+ bool const is_ntp_sync_timeout = (current_tick - _last_ntp_sync_tick) > _ntp_sync_interval_ms ;
128129 if (!_is_rtc_configured || is_ntp_sync_timeout) {
129130 sync ();
130131 }
@@ -148,6 +149,11 @@ bool TimeService::sync()
148149 return _is_rtc_configured;
149150}
150151
152+ void TimeService::setSyncInterval (unsigned long seconds)
153+ {
154+ _ntp_sync_interval_ms = seconds * 1000 ;
155+ }
156+
151157void TimeService::setTimeZoneData (long offset, unsigned long dst_until)
152158{
153159 if (_timezone_offset != offset)
0 commit comments