TimeClient up and running

pull/125/head
Robert Stein 2020-12-13 16:51:40 +01:00
parent adc6937259
commit 9fd1f8e590
3 changed files with 31 additions and 3 deletions

View File

@ -1,8 +1,23 @@
#include "TimeClient.h"
TimeClient::TimeClient(float utcOffset, DebugController * debugController) {
this->myUtcOffset = utcOffset;
this->debugController = debugController;
this->myUtcOffset = utcOffset;
this->debugController = debugController;
}
void TimeClient::handleSync(int snycDelayMinutes) {
//Get Time Update
if((this->getMinutesFromLastRefresh() >= snycDelayMinutes) || this->lastEpoch == 0) {
this->debugController->printLn("Updating Time...");
this->updateTime();
this->lastEpoch = this->getCurrentEpoch();
this->debugController->printLn("Local time: " + this->getAmPmFormattedTime());
}
}
int TimeClient::getMinutesFromLastRefresh() {
int minutes = (this->getCurrentEpoch() - this->lastEpoch) / 60;
return minutes;
}
void TimeClient::updateTime() {

View File

@ -14,10 +14,15 @@ private:
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
DebugController * debugController;
long lastEpoch = 0;
long firstEpoch = 0;
public:
TimeClient(float utcOffset, DebugController * debugController);
void updateTime();
void handleSync(int snycDelayMinutes);
int getMinutesFromLastRefresh();
void setUtcOffset(float utcOffset);
String getHours();
String getAmPmHours();

View File

@ -2,6 +2,8 @@
#include <ArduinoOTA.h>
void configModeCallback(WiFiManager *myWiFiManager);
@ -75,6 +77,12 @@ void setup() {
}
void loop() {
// Handle update of time
timeClient.handleSync(globalDataController.getClockResyncMinutes());
// put your main code here, to run repeatedly: