try to fix #408 and #412

This commit is contained in:
MichaelDvP
2022-03-29 15:30:39 +02:00
parent 80c87c8c43
commit 786a94b448
6 changed files with 33 additions and 5 deletions

View File

@@ -46,8 +46,10 @@ void NTPSettingsService::WiFiEvent(WiFiEvent_t event) {
// https://werner.rothschopf.net/microcontroller/202103_arduino_esp32_ntp_en.htm
void NTPSettingsService::configureNTP() {
emsesp::EMSESP::system_.ntp_connected(false);
if (connected_ && _state.enabled) {
emsesp::EMSESP::logger().info(F("Starting NTP"));
sntp_set_time_sync_notification_cb(ntp_received);
configTzTime(_state.tzFormat.c_str(), _state.server.c_str());
} else {
setenv("TZ", _state.tzFormat.c_str(), 1);
@@ -75,3 +77,8 @@ void NTPSettingsService::configureTime(AsyncWebServerRequest * request, JsonVari
AsyncWebServerResponse * response = request->beginResponse(400);
request->send(response);
}
void NTPSettingsService::ntp_received(struct timeval * tv) {
// emsesp::EMSESP::logger().info(F("NTP sync to %d sec"), tv->tv_sec);
emsesp::EMSESP::system_.ntp_connected(true);
}