-
Firmware: v1.0.1
+
Firmware:
IP:
Fetching...
@@ -2512,10 +2512,18 @@ opacity: 0.5;
// Fetch uptime from ESP
function fetchUptime() {
fetch("/uptime")
- .then((res) => res.text())
- .then((text) => {
- uptimeSeconds = parseUptimeToSeconds(text);
+ .then((res) => res.json())
+ .then((data) => {
+ // Get raw seconds from firmware
+ uptimeSeconds = data.uptime_seconds || 0;
+ // Update uptime display immediately
updateUptimeDisplay();
+ // Update firmware version in UI
+ const versionEl = document.getElementById("fwVersion");
+ if (versionEl) {
+ versionEl.textContent = "v" + data.version;
+ }
+ // Restart local increment timer
if (uptimeTimer) clearInterval(uptimeTimer);
uptimeTimer = setInterval(() => {
uptimeSeconds++;
@@ -2525,23 +2533,6 @@ opacity: 0.5;
.catch((err) => console.error("Error fetching /uptime:", err));
}
- // Convert "14:56:54" or "2d 03:12:33" → total seconds
- function parseUptimeToSeconds(text) {
- let days = 0,
- h = 0,
- m = 0,
- s = 0;
- const dayMatch = text.match(/(\d+)\s*(?:d|day)/i);
- if (dayMatch) days = parseInt(dayMatch[1]);
- const timeMatch = text.match(/(\d+):(\d+):(\d+)/);
- if (timeMatch) {
- h = parseInt(timeMatch[1]);
- m = parseInt(timeMatch[2]);
- s = parseInt(timeMatch[3]);
- }
- return days * 86400 + h * 3600 + m * 60 + s;
- }
-
// Format seconds → "2 days 04:09:31", "1 day 03:05:12", or "03:05:12"
function formatUptime(seconds) {
const days = Math.floor(seconds / 86400);
diff --git a/ESPTimeCast_ESP8266/ESPTimeCast_ESP8266.ino b/ESPTimeCast_ESP8266/ESPTimeCast_ESP8266.ino
index 10e8d36..86a4770 100644
--- a/ESPTimeCast_ESP8266/ESPTimeCast_ESP8266.ino
+++ b/ESPTimeCast_ESP8266/ESPTimeCast_ESP8266.ino
@@ -20,6 +20,7 @@
#include "months_lookup.h" // Languages for the Months of the Year
#include "index_html.h" // Web UI
+#define FIRMWARE_VERSION "1.0.1"
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CLK_PIN 14 //D5
@@ -1525,22 +1526,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();
-
- 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_ESP8266/index_html.h b/ESPTimeCast_ESP8266/index_html.h
index ad9af2b..1588df5 100644
--- a/ESPTimeCast_ESP8266/index_html.h
+++ b/ESPTimeCast_ESP8266/index_html.h
@@ -1451,7 +1451,7 @@ opacity: 0.5;
- Firmware: v1.0.1
+ Firmware:
IP:
Fetching...
@@ -2512,10 +2512,18 @@ opacity: 0.5;
// Fetch uptime from ESP
function fetchUptime() {
fetch("/uptime")
- .then((res) => res.text())
- .then((text) => {
- uptimeSeconds = parseUptimeToSeconds(text);
+ .then((res) => res.json())
+ .then((data) => {
+ // Get raw seconds from firmware
+ uptimeSeconds = data.uptime_seconds || 0;
+ // Update uptime display immediately
updateUptimeDisplay();
+ // Update firmware version in UI
+ const versionEl = document.getElementById("fwVersion");
+ if (versionEl) {
+ versionEl.textContent = "v" + data.version;
+ }
+ // Restart local increment timer
if (uptimeTimer) clearInterval(uptimeTimer);
uptimeTimer = setInterval(() => {
uptimeSeconds++;
@@ -2525,23 +2533,6 @@ opacity: 0.5;
.catch((err) => console.error("Error fetching /uptime:", err));
}
- // Convert "14:56:54" or "2d 03:12:33" → total seconds
- function parseUptimeToSeconds(text) {
- let days = 0,
- h = 0,
- m = 0,
- s = 0;
- const dayMatch = text.match(/(\d+)\s*(?:d|day)/i);
- if (dayMatch) days = parseInt(dayMatch[1]);
- const timeMatch = text.match(/(\d+):(\d+):(\d+)/);
- if (timeMatch) {
- h = parseInt(timeMatch[1]);
- m = parseInt(timeMatch[2]);
- s = parseInt(timeMatch[3]);
- }
- return days * 86400 + h * 3600 + m * 60 + s;
- }
-
// Format seconds → "2 days 04:09:31", "1 day 03:05:12", or "03:05:12"
function formatUptime(seconds) {
const days = Math.floor(seconds / 86400);