@@ -109,7 +109,7 @@ static time_t const EPOCH = 0;
109
109
**************************************************************************************/
110
110
111
111
TimeServiceClass::TimeServiceClass ()
112
- : _con_hdl (nullptr )
112
+ : _udp (nullptr )
113
113
, _is_rtc_configured(false )
114
114
, _is_tz_configured(false )
115
115
, _timezone_offset(24 * 60 * 60 )
@@ -125,13 +125,14 @@ TimeServiceClass::TimeServiceClass()
125
125
* PUBLIC MEMBER FUNCTIONS
126
126
**************************************************************************************/
127
127
128
- void TimeServiceClass::begin (ConnectionHandler * con_hdl )
128
+ void TimeServiceClass::begin (UDP & udp )
129
129
{
130
- _con_hdl = con_hdl;
131
130
initRTC ();
132
131
#ifdef HAS_LORA
133
132
setRTC (EPOCH_AT_COMPILE_TIME);
134
133
#endif
134
+
135
+ _udp = &udp;
135
136
}
136
137
137
138
unsigned long TimeServiceClass::getTime ()
@@ -179,6 +180,14 @@ bool TimeServiceClass::sync()
179
180
return _is_rtc_configured;
180
181
}
181
182
183
+ bool TimeServiceClass::isTimeValid ()
184
+ {
185
+ if (_is_rtc_configured) {
186
+ return isTimeValid (getRTC ());
187
+ }
188
+ return false ;
189
+ }
190
+
182
191
void TimeServiceClass::setSyncInterval (unsigned long seconds)
183
192
{
184
193
_sync_interval_ms = seconds * 1000 ;
@@ -276,34 +285,15 @@ unsigned long TimeServiceClass::getTimeFromString(const String& input)
276
285
**************************************************************************************/
277
286
278
287
#ifdef HAS_TCP
279
- bool TimeServiceClass::connected ()
280
- {
281
- if (_con_hdl == nullptr ) {
282
- return false ;
283
- } else {
284
- return _con_hdl->getStatus () == NetworkConnectionState::CONNECTED;
285
- }
286
- }
287
-
288
288
unsigned long TimeServiceClass::getRemoteTime ()
289
289
{
290
- if (connected ()) {
291
- /* At first try to obtain a valid time via NTP.
292
- * This is the most reliable time source and it will
293
- * ensure a correct behaviour of the library.
294
- */
295
- unsigned long const ntp_time = NTPUtils::getTime (_con_hdl->getUDP ());
296
- if (isTimeValid (ntp_time)) {
297
- return ntp_time;
298
- }
299
-
300
- /* As fallback if NTP request fails try to obtain the
301
- * network time using the connection handler.
302
- */
303
- unsigned long const connection_time = _con_hdl->getTime ();
304
- if (isTimeValid (connection_time)) {
305
- return connection_time;
306
- }
290
+ /* At first try to obtain a valid time via NTP.
291
+ * This is the most reliable time source and it will
292
+ * ensure a correct behaviour of the library.
293
+ */
294
+ unsigned long const ntp_time = NTPUtils::getTime (_udp);
295
+ if (isTimeValid (ntp_time)) {
296
+ return ntp_time;
307
297
}
308
298
309
299
/* Return the epoch timestamp at compile time as a last
0 commit comments