@@ -76,33 +76,20 @@ void TimeService::begin(ConnectionHandler * con_hdl)
76
76
77
77
unsigned long TimeService::getTime ()
78
78
{
79
- #ifdef ARDUINO_ARCH_SAMD
80
- if (!_is_rtc_configured)
81
- {
82
- unsigned long utc = getRemoteTime ();
83
- if (EPOCH_AT_COMPILE_TIME != utc)
84
- {
85
- rtc.setEpoch (utc);
86
- _is_rtc_configured = true ;
87
- }
88
- return utc;
79
+ unsigned long time = EPOCH_AT_COMPILE_TIME;
80
+
81
+ if (_is_rtc_configured) {
82
+ return get_rtc_time ();
89
83
}
90
- return rtc.getEpoch ();
91
- #elif ARDUINO_ARCH_MBED
92
- if (!_is_rtc_configured)
93
- {
94
- unsigned long utc = getRemoteTime ();
95
- if (EPOCH_AT_COMPILE_TIME != utc)
96
- {
97
- set_time (utc);
98
- _is_rtc_configured = true ;
99
- }
100
- return utc;
84
+
85
+ if (isConnected ()) {
86
+ time = getRemoteTime ();
101
87
}
102
- return time (NULL );
103
- #else
104
- return getRemoteTime ();
105
- #endif
88
+
89
+ if (time != EPOCH_AT_COMPILE_TIME) {
90
+ set_rtc_time (time );
91
+ }
92
+ return time ;
106
93
}
107
94
108
95
void TimeService::setTimeZoneData (long offset, unsigned long dst_until)
@@ -206,28 +193,26 @@ unsigned long TimeService::getRemoteTime()
206
193
#include " ../../AIoTC_Config.h"
207
194
#ifndef HAS_LORA
208
195
209
- if (isConnected ()) {
210
- /* At first try to see if a valid time can be obtained
211
- * using the network time available via the connection
212
- * handler.
213
- */
214
- unsigned long const connection_time = _con_hdl->getTime ();
215
- if (isTimeValid (connection_time)) {
216
- return connection_time;
217
- }
196
+ /* At first try to see if a valid time can be obtained
197
+ * using the network time available via the connection
198
+ * handler.
199
+ */
200
+ unsigned long const connection_time = _con_hdl->getTime ();
201
+ if (isTimeValid (connection_time)) {
202
+ return connection_time;
203
+ }
218
204
219
205
#ifndef __AVR__
220
- /* If no valid network time is available try to obtain the
221
- * time via NTP next.
222
- */
223
- unsigned long const ntp_time = NTPUtils::getTime (_con_hdl->getUDP ());
224
- if (isTimeValid (ntp_time)) {
225
- return ntp_time;
226
- }
206
+ /* If no valid network time is available try to obtain the
207
+ * time via NTP next.
208
+ */
209
+ unsigned long const ntp_time = NTPUtils::getTime (_con_hdl->getUDP ());
210
+ if (isTimeValid (ntp_time)) {
211
+ return ntp_time;
212
+ }
227
213
#endif
228
214
229
215
#endif /* ifndef HAS_LORA */
230
- }
231
216
232
217
/* Return the epoch timestamp at compile time as a last
233
218
* line of defense. Otherwise the certificate expiration
0 commit comments