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