adjusted health status check

This commit is contained in:
DJ2LS 2024-02-08 13:39:18 +01:00
parent 13e5f98b06
commit 3c9c115931
5 changed files with 24 additions and 15 deletions

View file

@ -6,15 +6,8 @@ setActivePinia(pinia);
import { useStateStore } from "../store/stateStore.js";
const state = useStateStore(pinia);
function getOverallHealth() {
//Return a number indicating health for icon bg color; lower the number the healthier
let health = 0;
if (state.modem_connection !== "connected") health += 5;
if (!state.is_modem_running) health += 3;
if (state.radio_status === false) health += 2;
if (process.env.FDUpdateAvail === "1") health += 1;
return health;
}
import { getOverallHealth } from "../js/eventHandler.js"
</script>
<template>
<a

View file

@ -19,7 +19,7 @@ async function apiGet(endpoint) {
}
return await response.json();
} catch (error) {
console.error("Error getting from REST:", error);
//console.error("Error getting from REST:", error);
}
}

View file

@ -129,6 +129,7 @@ export function eventDispatcher(data) {
displayToast("success", "bi-ethernet", message, 5000);
stateStore.modem_connection = "connected";
getModemState();
getOverallHealth();
getConfig();
getAudioDevices();
getSerialDevices();
@ -318,3 +319,18 @@ function build_HSL() {
}
stateStore.heard_stations.sort((a, b) => b.timestamp - a.timestamp); // b - a for reverse sort
}
export function getOverallHealth() {
//Return a number indicating health for icon bg color; lower the number the healthier
let health = 0;
if (stateStore.modem_connection !== "connected") {
health += 5;
stateStore.is_modem_running = false;
stateStore.radio_status = false;
}
if (!stateStore.is_modem_running) health += 3;
if (stateStore.radio_status === false) health += 2;
if (process.env.FDUpdateAvail === "1") health += 1;
return health;
}

View file

@ -19,7 +19,7 @@ function connect(endpoint, dispatcher) {
// handle opening
socket.addEventListener("open", function (event) {
console.log("Connected to the WebSocket server: " + endpoint);
//console.log("Connected to the WebSocket server: " + endpoint);
});
// handle data
@ -30,18 +30,18 @@ function connect(endpoint, dispatcher) {
// handle errors
socket.addEventListener("error", function (event) {
console.error("WebSocket error:", event);
//console.error("WebSocket error:", event);
connectionFailed(endpoint, event);
});
// handle closing and reconnect
socket.addEventListener("close", function (event) {
console.log("WebSocket connection closed:", event.code);
//console.log("WebSocket connection closed:", event.code);
// Reconnect handler
if (!event.wasClean) {
setTimeout(() => {
console.log("Reconnecting to websocket");
//console.log("Reconnecting to websocket");
connect(endpoint, dispatcher);
}, 1000);
}