Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions src/utility/time/TimeService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,32 +192,40 @@ unsigned long TimeService::getTimeFromString(const String& input)
* PRIVATE MEMBER FUNCTIONS
**************************************************************************************/

bool TimeService::connected()
{
if(_con_hdl == nullptr) {
return false;
} else {
return _con_hdl->getStatus() == NetworkConnectionState::CONNECTED;
}
}

unsigned long TimeService::getRemoteTime()
{
#include "../../AIoTC_Config.h"
#ifndef HAS_LORA

if(_con_hdl == nullptr)
return EPOCH_AT_COMPILE_TIME;

/* At first try to see if a valid time can be obtained
* using the network time available via the connection
* handler.
*/
unsigned long const connection_time = _con_hdl->getTime();
if(isTimeValid(connection_time)) {
return connection_time;
}
if(connected()) {
/* At first try to see if a valid time can be obtained
* using the network time available via the connection
* handler.
*/
unsigned long const connection_time = _con_hdl->getTime();
if(isTimeValid(connection_time)) {
return connection_time;
}

#ifndef __AVR__
/* If no valid network time is available try to obtain the
* time via NTP next.
*/
unsigned long const ntp_time = NTPUtils::getTime(_con_hdl->getUDP());
if(isTimeValid(ntp_time)) {
return ntp_time;
}
/* If no valid network time is available try to obtain the
* time via NTP next.
*/
unsigned long const ntp_time = NTPUtils::getTime(_con_hdl->getUDP());
if(isTimeValid(ntp_time)) {
return ntp_time;
}
#endif
}

#endif /* ifndef HAS_LORA */

Expand Down
1 change: 1 addition & 0 deletions src/utility/time/TimeService.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class TimeService
unsigned long _timezone_dst_until;

unsigned long getRemoteTime();
bool connected();
static bool isTimeValid(unsigned long const time);

};
Expand Down