Use ntp time sync at end of wifi activities

This commit is contained in:
jpirnay
2026-03-26 21:55:28 +01:00
parent 7f9456e8c6
commit 92877f9c36
9 changed files with 37 additions and 62 deletions
+14
View File
@@ -3,6 +3,7 @@
#include <Arduino.h>
#include <Logging.h>
#include <Preferences.h>
#include <WiFi.h>
#include <esp_private/esp_clk.h>
#include <esp_sntp.h>
#include <sys/time.h>
@@ -260,4 +261,17 @@ void formatLogTime(char* buf, size_t bufSize) {
snprintf(buf, bufSize, "%02d:%02d:%02d", timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec);
}
void wifiOff(bool skipNtpSync) {
if (!skipNtpSync && isApproximate() && WiFi.getMode() == WIFI_STA && WiFi.status() == WL_CONNECTED) {
syncNtp();
}
if (esp_sntp_enabled()) {
esp_sntp_stop();
}
WiFi.disconnect(false);
delay(100);
WiFi.mode(WIFI_OFF);
delay(100);
}
} // namespace HalClock