Add web dashboard configuration for master and slaves.
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>
This commit is contained in:
+186
-12
@@ -92,6 +92,32 @@
|
||||
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()">
|
||||
@@ -110,6 +136,12 @@
|
||||
</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">
|
||||
@@ -124,12 +156,25 @@
|
||||
<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-0">
|
||||
<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>
|
||||
@@ -140,9 +185,20 @@
|
||||
|
||||
<section class="col-lg-8">
|
||||
<div class="card h-100">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<span>ESP-NOW Clients</span>
|
||||
<span class="badge bg-secondary" x-text="(state.clients || []).length + ' registered'"></span>
|
||||
<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">
|
||||
@@ -153,14 +209,13 @@
|
||||
<th>MAC</th>
|
||||
<th>Ver</th>
|
||||
<th>Status</th>
|
||||
<th>Last ping</th>
|
||||
<th>Last OK</th>
|
||||
<th>Used</th>
|
||||
<th>Deadzone</th>
|
||||
<th>Aktion</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<template x-if="!(state.clients || []).length">
|
||||
<tr><td colspan="7" class="text-muted text-center py-4">No clients</td></tr>
|
||||
<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>
|
||||
@@ -172,9 +227,27 @@
|
||||
:class="c.available ? 'badge-online' : 'badge-offline'"
|
||||
x-text="c.available ? 'available' : 'inactive'"></span>
|
||||
</td>
|
||||
<td x-text="c.last_ping + ' ms'"></td>
|
||||
<td x-text="c.last_success_ping + ' ms'"></td>
|
||||
<td x-text="c.used ? 'yes' : 'no'"></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>
|
||||
@@ -192,6 +265,12 @@
|
||||
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';
|
||||
@@ -203,7 +282,18 @@
|
||||
setTimeout(connect, 2000);
|
||||
};
|
||||
this.ws.onmessage = (e) => {
|
||||
try { this.state = JSON.parse(e.data); } catch (_) {}
|
||||
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();
|
||||
@@ -211,6 +301,90 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user