TimeClient up and running
parent
adc6937259
commit
9fd1f8e590
|
|
@ -5,6 +5,21 @@ TimeClient::TimeClient(float utcOffset, DebugController * debugController) {
|
||||||
this->debugController = debugController;
|
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() {
|
void TimeClient::updateTime() {
|
||||||
WiFiClient client;
|
WiFiClient client;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,14 @@ private:
|
||||||
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
|
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
|
||||||
DebugController * debugController;
|
DebugController * debugController;
|
||||||
|
|
||||||
|
long lastEpoch = 0;
|
||||||
|
long firstEpoch = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TimeClient(float utcOffset, DebugController * debugController);
|
TimeClient(float utcOffset, DebugController * debugController);
|
||||||
void updateTime();
|
void updateTime();
|
||||||
|
void handleSync(int snycDelayMinutes);
|
||||||
|
int getMinutesFromLastRefresh();
|
||||||
|
|
||||||
void setUtcOffset(float utcOffset);
|
void setUtcOffset(float utcOffset);
|
||||||
String getHours();
|
String getHours();
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void configModeCallback(WiFiManager *myWiFiManager);
|
void configModeCallback(WiFiManager *myWiFiManager);
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -75,6 +77,12 @@ void setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
|
// Handle update of time
|
||||||
|
timeClient.handleSync(globalDataController.getClockResyncMinutes());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// put your main code here, to run repeatedly:
|
// put your main code here, to run repeatedly:
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue