Serve polls the master over UART and pushes live state via WebSocket; reopens the serial port when the device is unplugged and comes back. Co-authored-by: Cursor <cursoragent@cursor.com>
220 lines
7.4 KiB
HTML
220 lines
7.4 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;
|
|
}
|
|
</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">
|
|
<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-0">
|
|
<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>
|
|
</dl>
|
|
</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">
|
|
<span>ESP-NOW Clients</span>
|
|
<span class="badge bg-secondary" x-text="(state.clients || []).length + ' registered'"></span>
|
|
</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>Last ping</th>
|
|
<th>Last OK</th>
|
|
<th>Used</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>
|
|
</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.last_ping + ' ms'"></td>
|
|
<td x-text="c.last_success_ping + ' ms'"></td>
|
|
<td x-text="c.used ? 'yes' : 'no'"></td>
|
|
</tr>
|
|
</template>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
</main>
|
|
|
|
<script>
|
|
function dashboard() {
|
|
return {
|
|
state: { master: {}, clients: [] },
|
|
ws: null,
|
|
wsConnected: 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 { this.state = JSON.parse(e.data); } catch (_) {}
|
|
};
|
|
};
|
|
connect();
|
|
},
|
|
formatMac(hex) {
|
|
if (!hex || hex.length !== 12) return hex || '';
|
|
return hex.match(/.{2}/g).join(':');
|
|
}
|
|
};
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|