Expose deadzone and unicast-test via HTTP API and UI, reusing the same UART commands as the CLI. Co-authored-by: Cursor <cursoragent@cursor.com>
394 lines
14 KiB
HTML
394 lines
14 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Powerpod Dashboard</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.14.1/dist/cdn.min.js"></script>
|
|
<style>
|
|
:root {
|
|
--pp-bg: #0f1419;
|
|
--pp-surface: #1a1f26;
|
|
--pp-surface-raised: #222831;
|
|
--pp-border: #3d4449;
|
|
--pp-text: #f0f3f5;
|
|
--pp-text-secondary: #c5cdd6;
|
|
--pp-text-muted: #9aa8b5;
|
|
--pp-heading: #ffffff;
|
|
--pp-accent: #8ec8ff;
|
|
}
|
|
|
|
body {
|
|
background: var(--pp-bg);
|
|
color: var(--pp-text);
|
|
min-height: 100vh;
|
|
}
|
|
|
|
.navbar {
|
|
background: var(--pp-surface) !important;
|
|
border-bottom: 1px solid var(--pp-border);
|
|
}
|
|
.navbar-brand { color: var(--pp-heading) !important; }
|
|
|
|
.card {
|
|
background: var(--pp-surface);
|
|
border-color: var(--pp-border);
|
|
color: var(--pp-text);
|
|
}
|
|
.card-header {
|
|
background: var(--pp-surface-raised);
|
|
border-color: var(--pp-border);
|
|
color: var(--pp-heading);
|
|
font-weight: 600;
|
|
}
|
|
|
|
.text-muted { color: var(--pp-text-muted) !important; }
|
|
|
|
dl dt.text-muted {
|
|
color: var(--pp-text-secondary) !important;
|
|
font-weight: 500;
|
|
}
|
|
dl dd { color: var(--pp-text); }
|
|
|
|
.badge-online { background: #00a86b; color: #fff; }
|
|
.badge-offline { background: #5c6570; color: #f0f3f5; }
|
|
.badge.bg-secondary { background: #4a5560 !important; color: #f0f3f5; }
|
|
|
|
.mac {
|
|
font-family: ui-monospace, monospace;
|
|
font-size: 0.85rem;
|
|
color: var(--pp-accent);
|
|
}
|
|
|
|
.pp-table {
|
|
--bs-table-color: var(--pp-text);
|
|
--bs-table-bg: transparent;
|
|
--bs-table-border-color: var(--pp-border);
|
|
--bs-table-hover-color: var(--pp-heading);
|
|
--bs-table-hover-bg: rgba(255, 255, 255, 0.04);
|
|
margin-bottom: 0;
|
|
}
|
|
.pp-table thead th {
|
|
color: var(--pp-text-secondary);
|
|
font-weight: 600;
|
|
border-color: var(--pp-border);
|
|
background: var(--pp-surface-raised);
|
|
}
|
|
.pp-table tbody td {
|
|
color: var(--pp-text);
|
|
border-color: var(--pp-border);
|
|
vertical-align: middle;
|
|
}
|
|
.pp-table tbody tr:hover td { color: var(--pp-heading); }
|
|
|
|
.alert-danger {
|
|
background: rgba(220, 53, 69, 0.2);
|
|
border-color: #e35d6a;
|
|
color: #ffb3ba;
|
|
}
|
|
.alert-warning {
|
|
background: rgba(255, 193, 7, 0.15);
|
|
border-color: #d4a012;
|
|
color: #ffe08a;
|
|
}
|
|
.alert-success {
|
|
background: rgba(0, 168, 107, 0.15);
|
|
border-color: #00a86b;
|
|
color: #b8f0d8;
|
|
}
|
|
|
|
.form-control, .form-control:focus, .btn-outline-secondary {
|
|
background: var(--pp-surface-raised);
|
|
border-color: var(--pp-border);
|
|
color: var(--pp-text);
|
|
}
|
|
.form-control:focus {
|
|
box-shadow: 0 0 0 0.2rem rgba(142, 200, 255, 0.2);
|
|
border-color: var(--pp-accent);
|
|
}
|
|
.form-control::placeholder { color: var(--pp-text-muted); }
|
|
.btn-outline-secondary:hover {
|
|
background: var(--pp-border);
|
|
color: var(--pp-heading);
|
|
}
|
|
.btn-primary {
|
|
background: #2d6cdf;
|
|
border-color: #2d6cdf;
|
|
}
|
|
.btn-sm { font-size: 0.8rem; }
|
|
.dz-input { width: 5.5rem; }
|
|
</style>
|
|
</head>
|
|
<body x-data="dashboard()" x-init="connect()">
|
|
<nav class="navbar navbar-dark mb-4">
|
|
<div class="container-fluid">
|
|
<span class="navbar-brand mb-0 h1">Powerpod</span>
|
|
<span class="d-flex align-items-center gap-2">
|
|
<span class="badge rounded-pill me-1"
|
|
:class="state.uart_connected ? 'badge-online' : 'badge-offline'"
|
|
x-text="state.uart_connected ? 'UART' : 'UART off'"></span>
|
|
<span class="badge rounded-pill" :class="wsConnected ? 'badge-online' : 'badge-offline'"
|
|
x-text="wsConnected ? 'WS' : 'WS off'"></span>
|
|
<small class="text-muted ms-2" x-text="state.updated_at || '—'"></small>
|
|
</span>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="container pb-5">
|
|
<template x-if="configMsg">
|
|
<div class="alert py-2 mb-3"
|
|
:class="configMsgOk ? 'alert-success' : 'alert-danger'"
|
|
x-text="configMsg"></div>
|
|
</template>
|
|
|
|
<div class="row g-4">
|
|
<section class="col-lg-4">
|
|
<div class="card h-100">
|
|
<div class="card-header">Master</div>
|
|
<div class="card-body">
|
|
<p class="text-muted small mb-2" x-text="'UART ' + (state.serial_port || '—')"></p>
|
|
<template x-if="!state.uart_connected">
|
|
<div class="alert alert-warning py-2 mb-2"
|
|
x-text="state.serial_error || 'UART disconnected — reconnecting…'"></div>
|
|
</template>
|
|
<template x-if="state.uart_connected && !state.serial_ok">
|
|
<div class="alert alert-danger py-2" x-text="state.serial_error || 'Serial error'"></div>
|
|
</template>
|
|
<template x-if="state.master?.ok">
|
|
<dl class="row mb-3">
|
|
<dt class="col-5 text-muted">Version</dt>
|
|
<dd class="col-7" x-text="state.master.version"></dd>
|
|
<dt class="col-5 text-muted">Git</dt>
|
|
<dd class="col-7 text-break" x-text="state.master.git_hash"></dd>
|
|
<dt class="col-5 text-muted">Deadzone</dt>
|
|
<dd class="col-7" x-text="state.master.deadzone != null ? state.master.deadzone + ' LSB' : '—'"></dd>
|
|
</dl>
|
|
<div class="d-flex flex-wrap gap-2 align-items-center" x-show="state.uart_connected">
|
|
<input type="number" class="form-control form-control-sm dz-input"
|
|
min="0" max="4095" placeholder="LSB"
|
|
x-model.number="masterDz"
|
|
:disabled="busy">
|
|
<button type="button" class="btn btn-primary btn-sm"
|
|
@click="setDeadzone(0, masterDz)"
|
|
:disabled="busy || !state.uart_connected">
|
|
Master setzen
|
|
</button>
|
|
</div>
|
|
</template>
|
|
<template x-if="state.master && !state.master.ok">
|
|
<div class="alert alert-warning py-2" x-text="state.master.error"></div>
|
|
</template>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<section class="col-lg-8">
|
|
<div class="card h-100">
|
|
<div class="card-header d-flex justify-content-between align-items-center flex-wrap gap-2">
|
|
<span>ESP-NOW Slaves</span>
|
|
<div class="d-flex align-items-center gap-2">
|
|
<input type="number" class="form-control form-control-sm dz-input"
|
|
min="0" max="4095" placeholder="LSB"
|
|
x-model.number="allDz"
|
|
:disabled="busy">
|
|
<button type="button" class="btn btn-outline-secondary btn-sm"
|
|
@click="setDeadzoneAll(allDz)"
|
|
:disabled="busy || !state.uart_connected">
|
|
Alle Slaves
|
|
</button>
|
|
<span class="badge bg-secondary" x-text="(state.clients || []).length + ' registered'"></span>
|
|
</div>
|
|
</div>
|
|
<div class="card-body p-0">
|
|
<div class="table-responsive">
|
|
<table class="table pp-table table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>MAC</th>
|
|
<th>Ver</th>
|
|
<th>Status</th>
|
|
<th>Deadzone</th>
|
|
<th>Aktion</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<template x-if="!(state.clients || []).length">
|
|
<tr><td colspan="6" class="text-muted text-center py-4">No clients</td></tr>
|
|
</template>
|
|
<template x-for="c in (state.clients || [])" :key="c.id + c.mac">
|
|
<tr>
|
|
<td x-text="c.id"></td>
|
|
<td class="mac" x-text="formatMac(c.mac)"></td>
|
|
<td x-text="c.version"></td>
|
|
<td>
|
|
<span class="badge rounded-pill"
|
|
:class="c.available ? 'badge-online' : 'badge-offline'"
|
|
x-text="c.available ? 'available' : 'inactive'"></span>
|
|
</td>
|
|
<td x-text="c.deadzone != null ? c.deadzone : '—'"></td>
|
|
<td>
|
|
<div class="d-flex flex-wrap gap-1 align-items-center">
|
|
<input type="number" class="form-control form-control-sm dz-input"
|
|
min="0" max="4095"
|
|
:placeholder="String(c.deadzone || 100)"
|
|
x-model.number="slaveDz[c.id]"
|
|
:disabled="busy">
|
|
<button type="button" class="btn btn-primary btn-sm"
|
|
@click="setDeadzone(c.id, slaveDz[c.id] ?? c.deadzone ?? 100)"
|
|
:disabled="busy || !state.uart_connected || !c.available">
|
|
Setzen
|
|
</button>
|
|
<button type="button" class="btn btn-outline-secondary btn-sm"
|
|
@click="unicastTest(c.id)"
|
|
:disabled="busy || !state.uart_connected || !c.available"
|
|
title="ESP-NOW Unicast-Test">
|
|
Test
|
|
</button>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
</template>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
</main>
|
|
|
|
<script>
|
|
function dashboard() {
|
|
return {
|
|
state: { master: {}, clients: [] },
|
|
ws: null,
|
|
wsConnected: false,
|
|
masterDz: 100,
|
|
allDz: 100,
|
|
slaveDz: {},
|
|
busy: false,
|
|
configMsg: '',
|
|
configMsgOk: false,
|
|
connect() {
|
|
const proto = location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
const url = proto + '//' + location.host + '/ws';
|
|
const connect = () => {
|
|
this.ws = new WebSocket(url);
|
|
this.ws.onopen = () => { this.wsConnected = true; };
|
|
this.ws.onclose = () => {
|
|
this.wsConnected = false;
|
|
setTimeout(connect, 2000);
|
|
};
|
|
this.ws.onmessage = (e) => {
|
|
try {
|
|
const st = JSON.parse(e.data);
|
|
this.state = st;
|
|
if (st.master?.deadzone != null) {
|
|
this.masterDz = st.master.deadzone;
|
|
}
|
|
for (const c of (st.clients || [])) {
|
|
if (c.deadzone != null && this.slaveDz[c.id] == null) {
|
|
this.slaveDz[c.id] = c.deadzone;
|
|
}
|
|
}
|
|
} catch (_) {}
|
|
};
|
|
};
|
|
connect();
|
|
},
|
|
formatMac(hex) {
|
|
if (!hex || hex.length !== 12) return hex || '';
|
|
return hex.match(/.{2}/g).join(':');
|
|
},
|
|
flash(msg, ok) {
|
|
this.configMsg = msg;
|
|
this.configMsgOk = ok;
|
|
setTimeout(() => { this.configMsg = ''; }, 5000);
|
|
},
|
|
async setDeadzone(clientId, deadzone) {
|
|
if (deadzone == null || deadzone < 0) {
|
|
this.flash('Ungültiger Deadzone-Wert', false);
|
|
return;
|
|
}
|
|
this.busy = true;
|
|
try {
|
|
const r = await fetch('/api/deadzone', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
write: true,
|
|
deadzone: deadzone,
|
|
client_id: clientId,
|
|
all_clients: false
|
|
})
|
|
});
|
|
const data = await r.json();
|
|
if (!r.ok || !data.success) {
|
|
this.flash(data.error || `Deadzone für Client ${clientId} fehlgeschlagen`, false);
|
|
return;
|
|
}
|
|
const who = clientId === 0 ? 'Master' : `Slave ${clientId}`;
|
|
this.flash(`${who}: Deadzone ${data.deadzone} LSB gesetzt`, true);
|
|
} catch (e) {
|
|
this.flash(String(e), false);
|
|
} finally {
|
|
this.busy = false;
|
|
}
|
|
},
|
|
async setDeadzoneAll(deadzone) {
|
|
if (deadzone == null || deadzone < 0) {
|
|
this.flash('Ungültiger Deadzone-Wert', false);
|
|
return;
|
|
}
|
|
this.busy = true;
|
|
try {
|
|
const r = await fetch('/api/deadzone', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
write: true,
|
|
deadzone: deadzone,
|
|
client_id: 0,
|
|
all_clients: true
|
|
})
|
|
});
|
|
const data = await r.json();
|
|
if (!r.ok || !data.success) {
|
|
this.flash(data.error || 'Deadzone für alle Slaves fehlgeschlagen', false);
|
|
return;
|
|
}
|
|
this.flash(`Alle Slaves: Deadzone ${data.deadzone} LSB (${data.slaves_updated} per ESP-NOW)`, true);
|
|
} catch (e) {
|
|
this.flash(String(e), false);
|
|
} finally {
|
|
this.busy = false;
|
|
}
|
|
},
|
|
async unicastTest(clientId) {
|
|
this.busy = true;
|
|
try {
|
|
const r = await fetch('/api/unicast-test', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ client_id: clientId, seq: Date.now() % 100000 })
|
|
});
|
|
const data = await r.json();
|
|
if (!r.ok || !data.success) {
|
|
this.flash(data.error || `Unicast-Test Slave ${clientId} fehlgeschlagen`, false);
|
|
return;
|
|
}
|
|
this.flash(`Unicast-Test Slave ${clientId} OK (seq ${data.seq})`, true);
|
|
} catch (e) {
|
|
this.flash(String(e), false);
|
|
} finally {
|
|
this.busy = false;
|
|
}
|
|
}
|
|
};
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|