update time daily at 4 AM using task
This commit is contained in:
parent
8f706fe32f
commit
8a955fa43a
@ -83,7 +83,7 @@ namespace Display {
|
||||
if (currentHour != hour()) {
|
||||
currentHour = hour();
|
||||
if (currentHour == 4) {
|
||||
Ntp::updateTime();
|
||||
Ntp::tUpdateTime.restart();
|
||||
}
|
||||
if (currentHour == 8) {
|
||||
Brightness::set(BRIGHTNESS_DAY);
|
||||
|
||||
@ -14,16 +14,16 @@ namespace Ntp {
|
||||
TimeChangeRule CET = { "CET ", Last, Sun, Oct, 3, 60 }; // Central European Standard Time
|
||||
Timezone CE(CEST, CET);
|
||||
|
||||
void updateTime() {
|
||||
Task tUpdateTime(TASK_IMMEDIATE, TASK_ONCE, []{
|
||||
if (timeClient.forceUpdate()) {
|
||||
time_t newTime = CE.toLocal(timeClient.getEpochTime());
|
||||
setTime(newTime);
|
||||
Serial.println(asctime(localtime(&newTime)));
|
||||
}
|
||||
}
|
||||
}, &ts);
|
||||
|
||||
void setup() {
|
||||
timeClient.begin();
|
||||
Serial.println("NTP setup");
|
||||
timeClient.begin();
|
||||
}
|
||||
}
|
||||
@ -84,7 +84,7 @@ void onWifiConnected() {
|
||||
Wifi::printStatus();
|
||||
Ota::tLoop.enable();
|
||||
Mqtt::tReConnect.enable();
|
||||
Ntp::updateTime();
|
||||
Ntp::tUpdateTime.enable();
|
||||
}
|
||||
|
||||
void checkWifiCallback() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user