Define CLIENT_POLL_INTERVAL (5 s) in app.py, cache a reading for 4.8 s and pass the interval to the page, so several clients share one inverter read instead of each triggering their own. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
672 lines
25 KiB
HTML
672 lines
25 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Deye Inverter Monitor</title>
|
|
<style>
|
|
:root {
|
|
--bg-color: #1a1a1a;
|
|
--card-bg: #2d2d2d;
|
|
--text-color: #e0e0e0;
|
|
--accent-color: #00d2ff;
|
|
--secondary-accent: #3a7bd5;
|
|
--font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
}
|
|
|
|
* {
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
background-color: var(--bg-color);
|
|
color: var(--text-color);
|
|
font-family: var(--font-family);
|
|
margin: 0;
|
|
padding: 20px;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
}
|
|
|
|
h1 {
|
|
font-weight: 300;
|
|
margin: 10px 0 20px;
|
|
}
|
|
|
|
#bms-container {
|
|
width: 100%;
|
|
max-width: 1000px;
|
|
}
|
|
|
|
body>h2,
|
|
#bms-container>h2 {
|
|
width: 100%;
|
|
max-width: 1000px;
|
|
margin: 30px 0 10px;
|
|
font-size: 1.3rem;
|
|
font-weight: 400;
|
|
color: #aaa;
|
|
}
|
|
|
|
.card {
|
|
position: relative;
|
|
overflow: hidden;
|
|
background-color: var(--card-bg);
|
|
border-radius: 12px;
|
|
padding: 24px 20px 20px;
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
|
}
|
|
|
|
.card::before {
|
|
content: '';
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 4px;
|
|
background: linear-gradient(90deg, var(--accent-color), var(--secondary-accent));
|
|
}
|
|
|
|
.card h2 {
|
|
margin: 0 0 15px 0;
|
|
font-size: 1.2rem;
|
|
color: #aaa;
|
|
font-weight: 400;
|
|
}
|
|
|
|
.value {
|
|
font-size: 2.5rem;
|
|
font-weight: 700;
|
|
color: #fff;
|
|
}
|
|
|
|
.unit {
|
|
font-size: 1rem;
|
|
color: #888;
|
|
margin-left: 5px;
|
|
}
|
|
|
|
.setting-row {
|
|
display: flex;
|
|
gap: 8px;
|
|
margin-top: 12px;
|
|
}
|
|
|
|
.setting-row input {
|
|
flex: 1;
|
|
min-width: 0;
|
|
padding: 8px 10px;
|
|
border-radius: 6px;
|
|
border: 1px solid #555;
|
|
background: #1a1a1a;
|
|
color: #fff;
|
|
font-size: 1.1rem;
|
|
}
|
|
|
|
.setting-row input.invalid {
|
|
border-color: #ff4444;
|
|
}
|
|
|
|
button {
|
|
padding: 8px 14px;
|
|
border: none;
|
|
border-radius: 6px;
|
|
background: var(--secondary-accent);
|
|
color: #fff;
|
|
font-size: 0.95rem;
|
|
cursor: pointer;
|
|
}
|
|
|
|
button:disabled {
|
|
opacity: 0.5;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
button.secondary {
|
|
background: #555;
|
|
}
|
|
|
|
.hint {
|
|
margin-top: 8px;
|
|
font-size: 0.8rem;
|
|
color: #888;
|
|
}
|
|
|
|
.settings-actions {
|
|
width: 100%;
|
|
max-width: 1000px;
|
|
margin-top: 15px;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 15px;
|
|
}
|
|
|
|
#write-msg {
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
#write-msg.ok {
|
|
color: #00ff88;
|
|
}
|
|
|
|
#write-msg.err {
|
|
color: #ff4444;
|
|
}
|
|
|
|
.status-bar {
|
|
margin-top: 40px;
|
|
padding: 10px 20px;
|
|
border-radius: 20px;
|
|
background-color: var(--card-bg);
|
|
font-size: 0.9rem;
|
|
color: #888;
|
|
}
|
|
|
|
.status-indicator {
|
|
display: inline-block;
|
|
width: 10px;
|
|
height: 10px;
|
|
border-radius: 50%;
|
|
background-color: #555;
|
|
margin-right: 8px;
|
|
}
|
|
|
|
.status-indicator.active {
|
|
background-color: #00ff88;
|
|
box-shadow: 0 0 10px #00ff88;
|
|
}
|
|
|
|
.status-indicator.warning {
|
|
background-color: #ffaa00;
|
|
box-shadow: 0 0 10px #ffaa00;
|
|
}
|
|
|
|
.status-indicator.error {
|
|
background-color: #ff4444;
|
|
box-shadow: 0 0 10px #ff4444;
|
|
}
|
|
|
|
@keyframes pulse {
|
|
0% {
|
|
opacity: 1;
|
|
}
|
|
|
|
50% {
|
|
opacity: 0.5;
|
|
}
|
|
|
|
100% {
|
|
opacity: 1;
|
|
}
|
|
}
|
|
|
|
.loading .value {
|
|
animation: pulse 1.5s infinite;
|
|
color: #666;
|
|
}
|
|
|
|
.dashboard {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
|
gap: 20px;
|
|
width: 100%;
|
|
max-width: 1000px;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<h1>Deye Inverter Monitor</h1>
|
|
|
|
<div class="dashboard">
|
|
<div class="card" id="card-input">
|
|
<h2>Grid Voltage (Input)</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="input-voltage">--</span><span class="unit">V</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card" id="card-output">
|
|
<h2>Output Voltage</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="output-voltage">--</span><span class="unit">V</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card" id="card-load">
|
|
<h2>Load Voltage</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="load-voltage">--</span><span class="unit">V</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card" id="card-grid-current">
|
|
<h2>Grid Current</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="grid-current">--</span><span class="unit">A</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card" id="card-clamp-current">
|
|
<h2>Grid Clamp Current</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="grid-clamp-current">--</span><span class="unit">A</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card" id="card-output-current">
|
|
<h2>Output Current</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="output-current">--</span><span class="unit">A</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<h2>Battery & PV</h2>
|
|
<div class="dashboard">
|
|
<div class="card">
|
|
<h2>Battery SOC</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="batt-soc">--</span><span class="unit">%</span>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<h2>Battery Voltage</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="batt-voltage">--</span><span class="unit">V</span>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<h2>Battery Current</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="batt-current">--</span><span class="unit">A</span>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<h2>Battery Power</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="batt-power">--</span><span class="unit">W</span>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<h2>Battery Temp</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="batt-temp">--</span><span class="unit">°C</span>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<h2>PV1 Power</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="pv1-power">--</span><span class="unit">W</span>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<h2>PV2 Power</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="pv2-power">--</span><span class="unit">W</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<h2>Control Status</h2>
|
|
<div class="dashboard">
|
|
<div class="card">
|
|
<h2>Grid Relay</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="grid-relay">--</span>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<h2>Gen Relay</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="gen-relay">--</span>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<h2>Max Charge I</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="max-charge">--</span><span class="unit">A</span>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<h2>Max Discharge I</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="max-discharge">--</span><span class="unit">A</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="bms-container"></div>
|
|
|
|
<h2>Settings</h2>
|
|
<div class="dashboard" id="settings">
|
|
{% for reg, spec in writable.items() %}
|
|
<div class="card" data-reg="{{ reg }}">
|
|
<h2>{{ spec.label }} (reg {{ reg }})</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="current-{{ reg }}">--</span><span class="unit">{{ spec.unit }}</span>
|
|
</div>
|
|
<div class="setting-row">
|
|
<input type="text" inputmode="numeric" id="input-{{ reg }}" autocomplete="off"
|
|
aria-label="New value for register {{ reg }}">
|
|
<button type="button" id="set-{{ reg }}">Set</button>
|
|
</div>
|
|
<div class="hint">Allowed: {{ spec.min }}–{{ spec.max }} {{ spec.unit }} (default {{ spec.default }})</div>
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
<div class="settings-actions">
|
|
<button type="button" class="secondary" id="set-defaults">Default</button>
|
|
<span id="write-msg"></span>
|
|
</div>
|
|
|
|
<h2>Advanced Control & Limits</h2>
|
|
<div class="dashboard">
|
|
<div class="card">
|
|
<h2>Max Grid Output</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="max-grid-output">--</span><span class="unit">W</span>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<h2>Gen Peak Shaving</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="gen-peak-shaving">--</span><span class="unit">W</span>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<h2>Grid Peak Shaving</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="grid-peak-shaving">--</span><span class="unit">W</span>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<h2>Discharge Voltage</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="discharge-voltage">--</span><span class="unit">V</span>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<h2>Charge I Limit</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="charge-i-limit">--</span><span class="unit">A</span>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<h2>Discharge I Limit</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="discharge-i-limit">--</span><span class="unit">A</span>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<h2>Real Time Cap</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="real-time-cap">--</span><span class="unit">%</span>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<h2>Real Time Voltage</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="real-time-voltage">--</span><span class="unit">V</span>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<h2>Real Time Current</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="real-time-current">--</span><span class="unit">A</span>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<h2>Max Charge I Limit</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="max-charge-i-limit">--</span><span class="unit">A</span>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<h2>Max Discharge I Limit</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="max-discharge-i-limit">--</span><span class="unit">A</span>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<h2>Lithium Type</h2>
|
|
<div class="value-container loading">
|
|
<span class="value" id="lithium-type">--</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="status-bar"><span class="status-indicator" id="status-dot"></span><span
|
|
id="status-text">Connecting...</span></div>
|
|
<script>const inputVoltageEl = document.getElementById('input-voltage');
|
|
const outputVoltageEl = document.getElementById('output-voltage');
|
|
const loadVoltageEl = document.getElementById('load-voltage');
|
|
const gridCurrentEl = document.getElementById('grid-current');
|
|
const gridClampCurrentEl = document.getElementById('grid-clamp-current');
|
|
const outputCurrentEl = document.getElementById('output-current');
|
|
const statusDot = document.getElementById('status-dot');
|
|
const statusText = document.getElementById('status-text');
|
|
const valueContainers = document.querySelectorAll('.value-container');
|
|
// Tolerate this many consecutive failed updates before greying out the cards.
|
|
const MAX_TOLERATED_ERRORS = 1;
|
|
let consecutiveErrors = 0;
|
|
let hasData = false;
|
|
|
|
const LITHIUM_TYPES = {
|
|
0: 'Pylon/SOLAX CAN', 1: 'Tianbangda RS485', 2: 'KOK', 3: 'Keith', 4: 'Tuopai',
|
|
5: 'Pylon RS485', 6: 'Jielis RS485', 7: 'Sunwoda RS485', 8: 'Xinruineng RS485',
|
|
9: 'Tianbangda 485', 10: 'Shenggao CAN'
|
|
};
|
|
|
|
// ---- Writable settings ----
|
|
const WRITABLE = {{ writable | tojson }};
|
|
const CURRENT_FIELDS = { 230: 'grid_charge_current', 293: 'grid_peak_shaving_power' };
|
|
const writeMsg = document.getElementById('write-msg');
|
|
const dirty = {};
|
|
|
|
// Strict check, mirrors the server: digits only, integer, inside the allowed range.
|
|
function checkValue(reg, text) {
|
|
const spec = WRITABLE[reg];
|
|
if (!/^\d+$/.test(text.trim())) return 'Enter a whole number (digits only)';
|
|
const n = Number(text.trim());
|
|
if (!Number.isSafeInteger(n) || n < spec.min || n > spec.max) {
|
|
return 'Must be ' + spec.min + '\u2013' + spec.max + ' ' + spec.unit;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function showMsg(text, ok) {
|
|
writeMsg.textContent = text;
|
|
writeMsg.className = ok ? 'ok' : 'err';
|
|
}
|
|
|
|
function setBusy(busy) {
|
|
document.querySelectorAll('#settings button, #set-defaults').forEach(b => b.disabled = busy);
|
|
}
|
|
|
|
async function writeRegisters(writes) {
|
|
const summary = Object.entries(writes)
|
|
.map(([reg, v]) => WRITABLE[reg].label + ' (reg ' + reg + ') = ' + v + ' ' + WRITABLE[reg].unit)
|
|
.join('\n');
|
|
if (!confirm('Write to the inverter?\n\n' + summary)) return;
|
|
setBusy(true);
|
|
showMsg('Writing...', true);
|
|
try {
|
|
const response = await fetch('/api/registers', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ writes }),
|
|
signal: AbortSignal.timeout(30000)
|
|
});
|
|
let result;
|
|
try { result = await response.json(); } catch (e) { throw new Error('HTTP ' + response.status); }
|
|
if (result.status !== 'success') throw new Error(result.message || 'Write failed');
|
|
for (const reg of Object.keys(result.applied)) {
|
|
dirty[reg] = false;
|
|
document.getElementById('input-' + reg).value = result.applied[reg];
|
|
document.getElementById('current-' + reg).textContent = result.applied[reg];
|
|
}
|
|
showMsg('Written and verified: ' + Object.entries(result.applied).map(([r, v]) => r + '=' + v).join(', '), true);
|
|
} catch (error) {
|
|
showMsg('Error: ' + error.message, false);
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}
|
|
|
|
for (const reg of Object.keys(WRITABLE)) {
|
|
const input = document.getElementById('input-' + reg);
|
|
input.addEventListener('input', () => {
|
|
dirty[reg] = true;
|
|
input.classList.toggle('invalid', input.value !== '' && checkValue(reg, input.value) !== null);
|
|
});
|
|
document.getElementById('set-' + reg).addEventListener('click', () => {
|
|
const problem = checkValue(reg, input.value);
|
|
if (problem) {
|
|
input.classList.add('invalid');
|
|
showMsg('Register ' + reg + ': ' + problem, false);
|
|
return;
|
|
}
|
|
writeRegisters({ [reg]: Number(input.value.trim()) });
|
|
});
|
|
}
|
|
|
|
document.getElementById('set-defaults').addEventListener('click', () => {
|
|
const writes = {};
|
|
for (const [reg, spec] of Object.entries(WRITABLE)) writes[reg] = spec.default;
|
|
writeRegisters(writes);
|
|
});
|
|
|
|
// Show the inverter's current values; don't overwrite a value the user is typing.
|
|
function updateSettings(data) {
|
|
for (const [reg, field] of Object.entries(CURRENT_FIELDS)) {
|
|
if (data[field] === undefined) continue;
|
|
document.getElementById('current-' + reg).textContent = data[field];
|
|
if (!dirty[reg]) document.getElementById('input-' + reg).value = data[field];
|
|
}
|
|
}
|
|
|
|
const BMS_FIELDS = [
|
|
['soc', 'SOC', '%'], ['voltage', 'Voltage', 'V'], ['current', 'Current', 'A'],
|
|
['temp', 'Temp', '°C'], ['charge_voltage', 'Charge Voltage', 'V'],
|
|
['charge_current_limit', 'Charge I Limit', 'A']
|
|
];
|
|
|
|
// One section per connected BMS pack; nothing is shown if no pack reports data.
|
|
function renderBms(packs) {
|
|
const container = document.getElementById('bms-container');
|
|
container.replaceChildren();
|
|
for (const pack of packs) {
|
|
const title = document.createElement('h2');
|
|
title.textContent = 'BMS Pack ' + pack.pack;
|
|
const grid = document.createElement('div');
|
|
grid.className = 'dashboard';
|
|
for (const [key, label, unit] of BMS_FIELDS) {
|
|
const card = document.createElement('div');
|
|
card.className = 'card';
|
|
const h = document.createElement('h2');
|
|
h.textContent = label;
|
|
const box = document.createElement('div');
|
|
box.className = 'value-container';
|
|
const val = document.createElement('span');
|
|
val.className = 'value';
|
|
val.textContent = pack[key];
|
|
const u = document.createElement('span');
|
|
u.className = 'unit';
|
|
u.textContent = unit;
|
|
box.append(val, u);
|
|
card.append(h, box);
|
|
grid.append(card);
|
|
}
|
|
container.append(title, grid);
|
|
}
|
|
}
|
|
|
|
async function fetchData() {
|
|
try {
|
|
const response = await fetch('/api/data', { signal: AbortSignal.timeout(15000) });
|
|
let data;
|
|
try {
|
|
data = await response.json();
|
|
} catch (e) {
|
|
throw new Error('HTTP ' + response.status);
|
|
}
|
|
|
|
if (data.status === 'success') {
|
|
// Basic
|
|
inputVoltageEl.textContent = data.input_voltage;
|
|
outputVoltageEl.textContent = data.output_voltage;
|
|
loadVoltageEl.textContent = data.load_voltage;
|
|
gridCurrentEl.textContent = data.grid_current;
|
|
gridClampCurrentEl.textContent = data.grid_clamp_current;
|
|
outputCurrentEl.textContent = data.output_current;
|
|
|
|
// Battery & PV
|
|
document.getElementById('batt-soc').textContent = data.batt_soc;
|
|
document.getElementById('batt-voltage').textContent = data.batt_voltage;
|
|
document.getElementById('batt-current').textContent = data.batt_current;
|
|
document.getElementById('batt-power').textContent = data.batt_power;
|
|
document.getElementById('batt-temp').textContent = data.batt_temp;
|
|
document.getElementById('pv1-power').textContent = data.pv1_power;
|
|
document.getElementById('pv2-power').textContent = data.pv2_power;
|
|
|
|
// Control Status
|
|
document.getElementById('grid-relay').textContent = data.grid_relay_status === 1 ? 'Closed' : data.grid_relay_status === 0 ? 'Open' : data.grid_relay_status;
|
|
document.getElementById('gen-relay').textContent = (data.gen_relay_status & 0xF) === 0 ? 'Open' : 'Closed (' + data.gen_relay_status + ')';
|
|
document.getElementById('max-charge').textContent = data.max_charge_current;
|
|
document.getElementById('max-discharge').textContent = data.max_discharge_current;
|
|
|
|
renderBms(data.bms_packs || []);
|
|
updateSettings(data);
|
|
|
|
// Advanced Control
|
|
document.getElementById('max-grid-output').textContent = data.max_grid_output_power;
|
|
document.getElementById('gen-peak-shaving').textContent = data.gen_peak_shaving_power;
|
|
document.getElementById('grid-peak-shaving').textContent = data.grid_peak_shaving_power;
|
|
document.getElementById('discharge-voltage').textContent = data.discharge_voltage;
|
|
document.getElementById('charge-i-limit').textContent = data.charge_current_limit;
|
|
document.getElementById('discharge-i-limit').textContent = data.discharge_current_limit;
|
|
document.getElementById('real-time-cap').textContent = data.real_time_capacity;
|
|
document.getElementById('real-time-voltage').textContent = data.real_time_voltage;
|
|
document.getElementById('real-time-current').textContent = data.real_time_current;
|
|
document.getElementById('max-charge-i-limit').textContent = data.max_charge_current_limit;
|
|
document.getElementById('max-discharge-i-limit').textContent = data.max_discharge_current_limit;
|
|
document.getElementById('lithium-type').textContent = LITHIUM_TYPES[data.lithium_battery_type] || data.lithium_battery_type;
|
|
|
|
consecutiveErrors = 0;
|
|
hasData = true;
|
|
statusDot.className = 'status-indicator active';
|
|
statusText.textContent = 'Connected';
|
|
|
|
valueContainers.forEach(el => el.classList.remove('loading'));
|
|
}
|
|
|
|
else {
|
|
throw new Error(data.message || 'Unknown error');
|
|
}
|
|
}
|
|
|
|
catch (error) {
|
|
console.error('Error fetching data:', error);
|
|
consecutiveErrors++;
|
|
if (hasData && consecutiveErrors <= MAX_TOLERATED_ERRORS) {
|
|
// A single failed update: keep the old values and just warn.
|
|
statusDot.className = 'status-indicator warning';
|
|
statusText.textContent = 'Update failed, retrying (' + error.message + ')';
|
|
} else {
|
|
statusDot.className = 'status-indicator error';
|
|
statusText.textContent = 'Error: ' + error.message;
|
|
document.querySelectorAll('.value-container').forEach(el => el.classList.add('loading'));
|
|
}
|
|
}
|
|
}
|
|
|
|
// Fetch immediately, then at the server-defined interval (CLIENT_POLL_INTERVAL in app.py)
|
|
fetchData();
|
|
setInterval(fetchData, {{ poll_interval_ms }});
|
|
</script>
|
|
</body>
|
|
|
|
</html> |