docs(wiki): session wrap-up — panel verified live, milestones, ops gotchas, next steps trimmed
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
---
|
||||
type: entity
|
||||
updated: 2026-07-11
|
||||
updated: 2026-07-12
|
||||
tags: [software, csms, backend, relays, auth]
|
||||
---
|
||||
|
||||
@@ -45,6 +45,9 @@ backend/ (run: venv\Scripts\python -m backend.main, from the repo root)
|
||||
- **Multi-user auth** (2026-07-11, replaced the interim `api_token`): username/password users with permission scopes — `charger:<cp>:<gun>`, `relay:<name>`, `admin` — full model in [[authorization]]. Stdlib crypto only (PBKDF2 + HMAC sessions). Zero users = open API (startup warns); bootstrap via `python -m backend.users add <name> --scopes admin`.
|
||||
- Remote starts run under the calling user's own idTag (`app-<name>`) → per-person session attribution. Since 2026-07-12 these tags are **validated directly against the user record** (never enrolled in the allowlist — the old synthetic "app token of <name>" entries are auto-dropped on startup), and the charger-side gate enforces the user's `charger:<cp>:<gun>` scopes too.
|
||||
- **Consumption tracking** (`store.py`, 2026-07-11): every `StartTransaction` opens a row in `backend.db` with a resolved "who" (allowlist name or username); `StopTransaction` closes it and computes Wh from the meter diff; `MeterValues` rows land in a `samples` table (energy/power/SoC, kW→W normalized). Transaction ids continue from `MAX(tx)` across restarts, and stop-by-tx falls back to the store so sessions running through a backend restart stay stoppable.
|
||||
- **Live telemetry** (2026-07-12): the latest meter sample per active transaction (SoC, W, V, A, energy) rides `/api/status` as `active_transactions[tx].telemetry`; `Transaction.Begin` snapshots are skipped (taken before the car's BMS is read). The `samples` table stores energy/power/SoC/voltage/current + OCPP context per minute.
|
||||
- Ctrl+C gotcha, fixed 2026-07-12: uvicorn's graceful shutdown waited forever for the charger's never-closing WebSocket — `timeout_graceful_shutdown=3` caps it; one Ctrl+C now exits in ~3 s and the charger redials.
|
||||
- SPA cache headers: `index.html` is `no-cache` (phones must revalidate — stale builds plagued early testing), hashed `assets/*` cache forever. Remember: **`:9000` serves the last `npm run build`** — source edits are invisible until a build runs (`npm run dev` for live editing).
|
||||
- Relay calls are blocking tinytuya I/O, run via `asyncio.to_thread` so the OCPP socket never stalls.
|
||||
- Venv at repo root (`../venv/`, Python 3.13); deps pinned in `backend/requirements.txt` (fastapi, uvicorn, websockets, ocpp, tinytuya) — the auth system added none.
|
||||
- Sessions record the **auth method** (`card` vs `app`) for the audit trail; unknown cards NEVER charge — they queue in `pending_cards` for admin approve/reject (learn mode is gone).
|
||||
|
||||
@@ -1,24 +1,25 @@
|
||||
---
|
||||
type: entity
|
||||
updated: 2026-07-11
|
||||
updated: 2026-07-12
|
||||
tags: [software, frontend, react]
|
||||
---
|
||||
|
||||
# Frontend (`../frontend/`)
|
||||
|
||||
The React control panel (built 2026-07-11, replacing the single-file vanilla-JS panel at the owner's request). Stack per the owner's spec: **Vite + TypeScript + React 19, React Router 7 (routing), zustand (auth/UI state), TanStack Query 5 (server state, polling)**.
|
||||
The React control panel — branded **"Art IoT"** by the owner (2026-07-12) — (built 2026-07-11, replacing the single-file vanilla-JS panel at the owner's request). Stack per the owner's spec: **Vite + TypeScript + React 19, React Router 7 (routing), zustand (auth/UI state), TanStack Query 5 (server state, polling)**.
|
||||
|
||||
## Dev / prod workflow
|
||||
|
||||
- **Dev**: `npm run dev` in `frontend/` → Vite on `:5173`, **proxies `/api` to the backend on `:9000`** (`vite.config.ts`), so the session cookie flows normally.
|
||||
- **Prod**: `npm run build` → `frontend/dist/`; the [[backend]] serves it statically with an SPA fallback (exact files win, everything else gets `index.html`, `/api/*` and `/docs` excluded). No separate web server.
|
||||
- Fully self-contained: fonts (Archivo + IBM Plex Mono via Fontsource) are bundled into `dist/` — nothing loads from a CDN, so it works over [[netbird|NetBird]] without internet. ~94 kB gzipped JS.
|
||||
- Fully self-contained: fonts (Archivo + IBM Plex Mono via Fontsource) are bundled into `dist/` — nothing loads from a CDN, so it works over [[netbird|NetBird]] without internet. ~95 kB gzipped JS.
|
||||
- ✅ **Verified on the owner's phone against the live charger** (2026-07-12): login, gun cards, and a real in-app remote start.
|
||||
|
||||
## Pages
|
||||
|
||||
| Route | Who | What |
|
||||
|---|---|---|
|
||||
| `/` (Control) | all | one "bay" card per gun — **every registry-declared gun always renders**, even offline; status lamp, Start/Stop gated by scope **and** gun readiness; live session shows who/via/duration; relay toggles with on-demand live read |
|
||||
| `/` (Control) | all | one "bay" card per gun — **every registry-declared gun always renders**, even offline; status lamp, Start/Stop gated by scope **and** cable-plugged readiness; a charging bay shows the **SoC battery gauge (red→blue→green fill)**, a big kW readout, delivered kWh, voltage, current, plus who/via/duration; relay toggles with on-demand live read |
|
||||
| `/account` | all | **your permissions in plain words** (admin badge, or the guns/relays you may control) + self-service password change (current password required) |
|
||||
| `/history` | all | admins: the full audit table (**who charged, via Card or In-app, which gun, when, duration, kWh**); everyone else: **only their own sessions** |
|
||||
| `/cards` | admin | **pending cards awaiting review** (approve → name + owner + gun restrictions in one step; reject → silenced), enrolled cards with owner/guns editing, rejected list with un-reject |
|
||||
|
||||
Reference in New Issue
Block a user