mirror of
https://github.com/mfactory-osaka/ESPTimeCast.git
synced 2026-02-19 11:54:56 -05:00
Firmware version loads directly from sketch
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -1451,7 +1451,7 @@ opacity: 0.5;
|
||||
<div class="sub-collapsible-content" aria-hidden="true">
|
||||
<div class="content-wrapper">
|
||||
<div class="toggle-padding device-info">
|
||||
<span>Firmware: v1.0.1</span><br><br>
|
||||
<span>Firmware: <span id="fwVersion"></span></span><br><br>
|
||||
<span>IP:
|
||||
<span id="ipDisplay">Fetching...</span>
|
||||
</span><br><br>
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -1451,7 +1451,7 @@ opacity: 0.5;
|
||||
<div class="sub-collapsible-content" aria-hidden="true">
|
||||
<div class="content-wrapper">
|
||||
<div class="toggle-padding device-info">
|
||||
<span>Firmware: v1.0.1</span><br><br>
|
||||
<span>Firmware: <span id="fwVersion"></span></span><br><br>
|
||||
<span>IP:
|
||||
<span id="ipDisplay">Fetching...</span>
|
||||
</span><br><br>
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user