TimeClient up and running
parent
adc6937259
commit
9fd1f8e590
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -14,9 +14,14 @@ 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();
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue