LoRa_APRS_iGate/src/TaskNTP.cpp

39 lines
775 B
C++
Raw Normal View History

#include <logger.h>
#include <TimeLib.h>
#include "project_configuration.h"
#include "TaskNTP.h"
2021-01-04 23:10:23 +01:00
#include "Task.h"
NTPTask::NTPTask()
2021-01-09 13:38:48 +01:00
: Task(TASK_NTP, TaskNtp), _beginCalled(false)
{
}
NTPTask::~NTPTask()
{
}
2021-01-04 23:10:23 +01:00
bool NTPTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig)
{
_ntpClient = std::shared_ptr<NTPClient>(new NTPClient(config->ntpServer.c_str()));
return true;
}
bool NTPTask::loop(std::shared_ptr<Configuration> config)
{
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;
}