From 441c61676b090152376a971d727efee8913d5496 Mon Sep 17 00:00:00 2001 From: Alex Petrochenko Date: Thu, 14 May 2026 17:20:08 +0100 Subject: [PATCH] fix: date timezone + weather periodic refresh (closes #5, #7) - Use localTime instead of epochTime when formatting date string, so date rolls over at local midnight, not UTC midnight (fixes #5) - Remove WEATHER_SUCCESS state assignment that blocked periodic refresh; state correctly stays WEATHER_IDLE after successful fetch (fixes #7) - Fix weather debug page "Last update" to show elapsed seconds (millis() - lastUpdate) instead of raw timestamp Applied from PR #6 by @Mysteoa with a compilation fix in web_server.cpp (missing closing parenthesis in snprintf_P call). Co-authored-by: Mysteoa Co-Authored-By: Claude Sonnet 4.6 --- firmware/clock_ntp_ota_v1.9/display.cpp | 2 +- firmware/clock_ntp_ota_v1.9/weather.cpp | 2 +- firmware/clock_ntp_ota_v1.9/web_server.cpp | 2 +- src/clock_ntp_ota_v1.9.ino | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/firmware/clock_ntp_ota_v1.9/display.cpp b/firmware/clock_ntp_ota_v1.9/display.cpp index d8b00b3..d3f0d2e 100644 --- a/firmware/clock_ntp_ota_v1.9/display.cpp +++ b/firmware/clock_ntp_ota_v1.9/display.cpp @@ -54,7 +54,7 @@ void ICACHE_FLASH_ATTR updateDisplay() { // === YELLOW ZONE (Y: 48-63): Date (size 2 = 16px height) === display.setTextSize(2); - time_t t = epochTime; + time_t t = localTime; struct tm *ptm = gmtime(&t); // Format: "Thu 02.01" or "! Thu 02.01" if no WiFi diff --git a/firmware/clock_ntp_ota_v1.9/weather.cpp b/firmware/clock_ntp_ota_v1.9/weather.cpp index 8a51a4e..be56690 100644 --- a/firmware/clock_ntp_ota_v1.9/weather.cpp +++ b/firmware/clock_ntp_ota_v1.9/weather.cpp @@ -83,7 +83,7 @@ void ICACHE_FLASH_ATTR onWeatherResponse(void* optParm, AsyncHTTPRequest* reques sunTimes.lastDay = ptm->tm_yday; } - weatherState = WEATHER_SUCCESS; + // weatherState stays WEATHER_IDLE (set at readyState==4 entry) — allows periodic refresh weatherRetry.reset(); Serial.printf("Weather: %.1f C, code %d, wind %.1f km/h\n", weather.temperature, weather.weathercode, weather.windspeed); diff --git a/firmware/clock_ntp_ota_v1.9/web_server.cpp b/firmware/clock_ntp_ota_v1.9/web_server.cpp index c17f40e..065ee7c 100644 --- a/firmware/clock_ntp_ota_v1.9/web_server.cpp +++ b/firmware/clock_ntp_ota_v1.9/web_server.cpp @@ -166,7 +166,7 @@ void ICACHE_FLASH_ATTR handleDebug() { if (weather.valid) { snprintf_P(buf, sizeof(buf), PSTR("Temperature: %.1f C\nWeather code: %d\nWind speed: %.1f km/h\nLast update: %lu sec ago\n"), - weather.temperature, weather.weathercode, weather.windspeed, weather.lastUpdate/1000); + weather.temperature, weather.weathercode, weather.windspeed, (millis() - weather.lastUpdate)/1000); server.sendContent(buf); } diff --git a/src/clock_ntp_ota_v1.9.ino b/src/clock_ntp_ota_v1.9.ino index 2e50da8..9bb2180 100644 --- a/src/clock_ntp_ota_v1.9.ino +++ b/src/clock_ntp_ota_v1.9.ino @@ -988,7 +988,7 @@ void updateDisplay() { // === YELLOW ZONE (Y: 48-63): Date (size 2 = 16px height) === display.setTextSize(2); - time_t t = epochTime; + time_t t = localTime; struct tm *ptm = gmtime(&t); // Format: "Thu 02.01" or "! Thu 02.01" if no WiFi @@ -1453,7 +1453,7 @@ void ICACHE_FLASH_ATTR handleDebug() { if (weather.valid) { snprintf_P(buf, sizeof(buf), PSTR("Temperature: %.1f°C\nWeather code: %d\nWind speed: %.1f km/h\nLast update: %lu sec ago\n"), - weather.temperature, weather.weathercode, weather.windspeed, weather.lastUpdate/1000); + weather.temperature, weather.weathercode, weather.windspeed, (millis() - weather.lastUpdate)/1000); server.sendContent(buf); } @@ -2081,7 +2081,7 @@ void onWeatherResponse(void* optParm, AsyncHTTPRequest* request, int readyState) sunTimes.lastDay = ptm->tm_yday; } - weatherState = WEATHER_SUCCESS; + // weatherState stays WEATHER_IDLE (set at readyState==4 entry) — allows periodic refresh weatherRetry.reset(); // Success! Reset retry counter Serial.printf("✓ Weather: %.1f°C, code %d, wind %.1f km/h\n", weather.temperature, weather.weathercode, weather.windspeed);