24
24
#include < time.h>
25
25
#include " TimeService.h"
26
26
#include " NTPUtils.h"
27
+ #include " AIoTC_Const.h"
27
28
28
29
#ifdef ARDUINO_ARCH_SAMD
29
30
#include < RTCZero.h>
@@ -90,8 +91,7 @@ unsigned long esp8266_getRTC();
90
91
**************************************************************************************/
91
92
92
93
/* 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 ;
95
95
static time_t const EPOCH_AT_COMPILE_TIME = cvt_time(__DATE__);
96
96
static time_t const EPOCH = 0 ;
97
97
@@ -106,6 +106,7 @@ TimeService::TimeService()
106
106
, _timezone_offset(0 )
107
107
, _timezone_dst_until(0 )
108
108
, _last_ntp_sync_tick(0 )
109
+ , _ntp_sync_interval_ms(TIMESERVICE_NTP_SYNC_TIMEOUT_ms)
109
110
{
110
111
111
112
}
@@ -124,7 +125,7 @@ unsigned long TimeService::getTime()
124
125
{
125
126
/* Check if it's time to sync */
126
127
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 ;
128
129
if (!_is_rtc_configured || is_ntp_sync_timeout) {
129
130
sync ();
130
131
}
@@ -148,6 +149,11 @@ bool TimeService::sync()
148
149
return _is_rtc_configured;
149
150
}
150
151
152
+ void TimeService::setSyncInterval (unsigned long seconds)
153
+ {
154
+ _ntp_sync_interval_ms = seconds * 1000 ;
155
+ }
156
+
151
157
void TimeService::setTimeZoneData (long offset, unsigned long dst_until)
152
158
{
153
159
if (_timezone_offset != offset)
0 commit comments