From 5b658979924d8e887a0524cb0317f6cf377143f5 Mon Sep 17 00:00:00 2001 From: M-Factory Date: Thu, 19 Feb 2026 17:30:32 +0900 Subject: [PATCH] Firmware version loads directly from sketch --- ESPTimeCast_ESP32/ESPTimeCast_ESP32.ino | 33 +++++++++++---------- ESPTimeCast_ESP32/index_html.h | 33 ++++++++------------- ESPTimeCast_ESP8266/ESPTimeCast_ESP8266.ino | 32 ++++++++++---------- ESPTimeCast_ESP8266/index_html.h | 33 ++++++++------------- 4 files changed, 58 insertions(+), 73 deletions(-) diff --git a/ESPTimeCast_ESP32/ESPTimeCast_ESP32.ino b/ESPTimeCast_ESP32/ESPTimeCast_ESP32.ino index ffa9f3f..37fdc9e 100644 --- a/ESPTimeCast_ESP32/ESPTimeCast_ESP32.ino +++ b/ESPTimeCast_ESP32/ESPTimeCast_ESP32.ino @@ -51,6 +51,7 @@ #error "Unsupported board!" #endif +#define FIRMWARE_VERSION "1.0.1" #define HARDWARE_TYPE MD_MAX72XX::FC16_HW #define MAX_DEVICES 4 @@ -1557,23 +1558,23 @@ void setupWebServer() { }); server.on("/uptime", HTTP_GET, [](AsyncWebServerRequest *request) { - if (!LittleFS.exists("/uptime.dat")) { - request->send(200, "text/plain", "No uptime recorded yet."); - return; + unsigned long seconds = 0; + String formatted = "No uptime recorded yet."; + if (LittleFS.exists("/uptime.dat")) { + File f = LittleFS.open("/uptime.dat", "r"); + if (f) { + String content = f.readString(); + seconds = content.toInt(); + formatted = formatUptime(seconds); + f.close(); + } } - - File f = LittleFS.open("/uptime.dat", "r"); - if (!f) { - request->send(500, "text/plain", "Error reading uptime file."); - return; - } - - String content = f.readString(); - f.close(); - - unsigned long seconds = content.toInt(); - String formatted = formatUptime(seconds); - request->send(200, "text/plain", formatted); + String json = "{"; + json += "\"uptime_seconds\":" + String(seconds) + ","; + json += "\"uptime_formatted\":\"" + formatted + "\","; + json += "\"version\":\"" FIRMWARE_VERSION "\""; + json += "}"; + request->send(200, "application/json", json); }); server.on("/export", HTTP_GET, [](AsyncWebServerRequest *request) { diff --git a/ESPTimeCast_ESP32/index_html.h b/ESPTimeCast_ESP32/index_html.h index ad9af2b..1588df5 100644 --- a/ESPTimeCast_ESP32/index_html.h +++ b/ESPTimeCast_ESP32/index_html.h @@ -1451,7 +1451,7 @@ opacity: 0.5;