cache control for tagtypes; uptime display in statusbar

This commit is contained in:
Nic Limper
2024-01-10 00:53:13 +01:00
parent 59d08ea21e
commit 3b294be08a
3 changed files with 44 additions and 2 deletions

View File

@@ -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));

View File

@@ -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;

View File

@@ -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;