From bd5f96d1b026e5f116c552ba49d0a27180d8277a Mon Sep 17 00:00:00 2001 From: Luc <8822552+luc-github@users.noreply.github.com> Date: Tue, 10 Sep 2024 10:18:31 +0800 Subject: [PATCH] Fix server name are not in fixed location Update esp8266 time code for consistency with esp32 --- esp3d/src/modules/time/time_service.cpp | 11 +++++------ esp3d/src/modules/time/time_service.h | 1 + 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/esp3d/src/modules/time/time_service.cpp b/esp3d/src/modules/time/time_service.cpp index 1d1f5f91..ed889242 100644 --- a/esp3d/src/modules/time/time_service.cpp +++ b/esp3d/src/modules/time/time_service.cpp @@ -78,7 +78,6 @@ bool TimeService::isInternetTime(bool readfromsettings) { bool TimeService::begin() { esp3d_log("Starting TimeService"); end(); - String s1, s2, s3, t1; updateTimeZone(true); #if defined(WIFI_FEATURE) // no time server in AP mode @@ -110,14 +109,14 @@ bool TimeService::begin() { if (!isInternetTime(true)) { return true; } - s1 = ESP3DSettings::readString(ESP_TIME_SERVER1); - s2 = ESP3DSettings::readString(ESP_TIME_SERVER2); - s3 = ESP3DSettings::readString(ESP_TIME_SERVER3); + _server[0] = ESP3DSettings::readString(ESP_TIME_SERVER1); + _server[1] = ESP3DSettings::readString(ESP_TIME_SERVER2); + _server[2] = ESP3DSettings::readString(ESP_TIME_SERVER3); #if defined(ARDUINO_ARCH_ESP32) - configTzTime(_time_zone_config.c_str(), s1.c_str(), s2.c_str(), s3.c_str()); + configTzTime(_time_zone_config.c_str(), _server[0].c_str(), _server[1].length() > 0 ? _server[1].c_str() : nullptr, _server[2].length() > 0 ? _server[2].c_str() : nullptr); #endif // ARDUINO_ARCH_ESP32 #if defined(ARDUINO_ARCH_ESP8266) - configTime(t1.c_str(), s1.c_str(), s2.c_str(), s3.c_str()); + configTime(_time_zone_config.c_str(), _server[0].c_str(), _server[1].length() > 0 ? _server[1].c_str() : nullptr, _server[2].length() > 0 ? _server[2].c_str() : nullptr); #endif // ARDUINO_ARCH_ESP8266 time_t now = time(nullptr); diff --git a/esp3d/src/modules/time/time_service.h b/esp3d/src/modules/time/time_service.h index f41fab21..1c26dbcd 100644 --- a/esp3d/src/modules/time/time_service.h +++ b/esp3d/src/modules/time/time_service.h @@ -44,6 +44,7 @@ class TimeService { int _get_time_zone_offset_min(); bool _started; bool _isInternetTime; + String _server[3]; String _time_zone; String _time_zone_config; };