diff --git a/ESP32_AP-Flasher/src/main.cpp b/ESP32_AP-Flasher/src/main.cpp index 327f08be..a33baa11 100644 --- a/ESP32_AP-Flasher/src/main.cpp +++ b/ESP32_AP-Flasher/src/main.cpp @@ -24,7 +24,7 @@ #include "web.h" util::Timer intervalContentRunner(seconds(1)); -util::Timer intervalSysinfo(seconds(3)); +util::Timer intervalSysinfo(seconds(5)); util::Timer intervalVars(seconds(10)); util::Timer intervalSaveDB(minutes(5)); diff --git a/ESP32_AP-Flasher/src/web.cpp b/ESP32_AP-Flasher/src/web.cpp index 99d5223b..786b57e7 100644 --- a/ESP32_AP-Flasher/src/web.cpp +++ b/ESP32_AP-Flasher/src/web.cpp @@ -91,6 +91,7 @@ void wsSendSysteminfo() { sys["rssi"] = WiFi.RSSI(); sys["wifistatus"] = WiFi.status(); sys["wifissid"] = WiFi.SSID(); + sys["uptime"] = esp_timer_get_time() / 1000000; static uint8_t day = 0; struct tm timeinfo; diff --git a/ESP32_AP-Flasher/wwwroot/main.js b/ESP32_AP-Flasher/wwwroot/main.js index c38bd053..32a7cef0 100644 --- a/ESP32_AP-Flasher/wwwroot/main.js +++ b/ESP32_AP-Flasher/wwwroot/main.js @@ -40,6 +40,7 @@ let otamodule; let socket; let finishedInitialLoading = false; let getTagtypeBusy = false; +let webVersion = "0"; const loadConfig = new Event("loadConfig"); window.addEventListener("loadConfig", function () { @@ -56,6 +57,7 @@ window.addEventListener("loadConfig", function () { }); window.addEventListener("load", function () { + initVersionInfo(); initTabs(); fetch('/content_cards.json') .then(response => response.json()) @@ -77,6 +79,20 @@ window.addEventListener("load", function () { populateTimes($('#apcnight2')); }); +function initVersionInfo() { + fetch('/version.txt') + .then(response => { + return response.text(); + }) + .then(data => { + webVersion = data; + console.log(webVersion); + }) + .catch(error => { + console.error('Fetch error:', error); + }); +} + /* tabs */ let activeTab = ''; function initTabs() { @@ -113,6 +129,30 @@ function loadTags(pos) { //.catch(error => showMessage('loadTags error: ' + error)); } +function formatUptime(seconds) { + const days = Math.floor(seconds / (24 * 60 * 60)); + const hours = Math.floor((seconds % (24 * 60 * 60)) / (60 * 60)); + const minutes = Math.floor((seconds % (60 * 60)) / 60); + const remainingSeconds = seconds % 60; + + const components = [ + { value: days, label: 'd' }, + { value: hours, label: 'h' }, + { value: minutes, label: 'm' }, + { value: remainingSeconds, label: 's' } + ]; + + let formattedUptime = ''; + + components.forEach(({ value, label }) => { + if (value > 0 || formattedUptime !== '') { + formattedUptime += `${value}${label} `; + } + }); + + return formattedUptime.trim(); +} + function connect() { protocol = location.protocol == "https:" ? "wss://" : "ws://"; socket = new WebSocket(protocol + location.host + "/ws"); @@ -152,6 +192,7 @@ function connect() { } else { str += `filesystem free: ${convertSize(msg.sys.littlefsfree)}`; } + str += ` ┇ uptime: ${formatUptime(msg.sys.uptime)}`; $("#sysinfo").innerHTML = str; @@ -1214,7 +1255,7 @@ async function getTagtype(hwtype) { try { getTagtypeBusy = true; tagTypes[hwtype] = { busy: true }; - const response = await fetch('/tagtypes/' + hwtype.toString(16).padStart(2, '0').toUpperCase() + '.json'); + const response = await fetch('/tagtypes/' + hwtype.toString(16).padStart(2, '0').toUpperCase() + '.json?' + webVersion); if (!response.ok) { let data = { name: 'unknown id ' + hwtype.toString(16), width: 0, height: 0, bpp: 0, rotatebuffer: 0, colortable: [], busy: false }; tagTypes[hwtype] = data;