mirror of
https://github.com/lora-aprs/LoRa_APRS_iGate.git
synced 2025-12-06 07:42:00 +01:00
36 lines
786 B
C++
36 lines
786 B
C++
#include <TimeLib.h>
|
|
#include <logger.h>
|
|
|
|
#include "Task.h"
|
|
#include "TaskNTP.h"
|
|
#include "project_configuration.h"
|
|
|
|
NTPTask::NTPTask() : Task(TASK_NTP, TaskNtp), _beginCalled(false) {
|
|
}
|
|
|
|
NTPTask::~NTPTask() {
|
|
}
|
|
|
|
bool NTPTask::setup(System &system) {
|
|
_ntpClient = std::shared_ptr<NTPClient>(new NTPClient(system.getUserConfig()->ntpServer.c_str()));
|
|
return true;
|
|
}
|
|
|
|
bool NTPTask::loop(System &system) {
|
|
if (!system.isWifiEthConnected()) {
|
|
return false;
|
|
}
|
|
if (!_beginCalled) {
|
|
_ntpClient->begin();
|
|
_beginCalled = true;
|
|
}
|
|
if (_ntpClient->update()) {
|
|
setTime(_ntpClient->getEpochTime());
|
|
logPrintI("Current time: ");
|
|
logPrintlnI(_ntpClient->getFormattedTime());
|
|
}
|
|
_stateInfo = _ntpClient->getFormattedTime();
|
|
_state = Okay;
|
|
return true;
|
|
}
|