From 12db2e719d03cbc029d7a622b85ab3a32487d33a Mon Sep 17 00:00:00 2001 From: Julian Cuni Date: Sun, 12 Jul 2026 10:13:36 +0200 Subject: [PATCH] =?UTF-8?q?docs(wiki):=20session=20wrap-up=20=E2=80=94=20p?= =?UTF-8?q?anel=20verified=20live,=20milestones,=20ops=20gotchas,=20next?= =?UTF-8?q?=20steps=20trimmed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wiki/concepts/authorization.md | 4 ++-- wiki/entities/backend.md | 5 ++++- wiki/entities/frontend.md | 9 +++++---- wiki/log.md | 4 ++++ wiki/overview.md | 18 +++++++++++------- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/wiki/concepts/authorization.md b/wiki/concepts/authorization.md index ee98cd7..82f6d87 100644 --- a/wiki/concepts/authorization.md +++ b/wiki/concepts/authorization.md @@ -40,9 +40,9 @@ Exhaustively tested on the real hardware; the charger never forwards any vehicle **Consequence:** vehicle-based auth is off the table. Households authorize via **RFID cards ✅** and the **app remote-start ✅** — both verified. (If a future firmware update changes this, retest with the same three steps.) -## 3. Mobile / web app — ✅ control path verified live (2026-07-09) +## 3. Mobile / web app — ✅ verified end-to-end (panel → live charger, 2026-07-12) -The exact calls the app will make were proven on the real charger with a car plugged in: `RemoteStartTransaction(connector=1, idTag="app-remote")` → Accepted → StartTransaction → Charging; `RemoteStopTransaction(tx)` → Accepted → StopTransaction (`reason: Remote`). Both guns ran **simultaneous transactions** (card on gun 2, remote on gun 1). The `app-remote` idTag is enrolled in the allowlist as `kind:"app"`. What remains is only the UI: +The exact calls the app will make were proven on the real charger with a car plugged in: `RemoteStartTransaction(connector=1, idTag="app-remote")` → Accepted → StartTransaction → Charging; `RemoteStopTransaction(tx)` → Accepted → StopTransaction (`reason: Remote`). Both guns ran **simultaneous transactions** (card on gun 2, remote on gun 1). The shared `app-remote` idTag used for that test is **retired** (2026-07-12): starts now run under per-user idTags, and the [[frontend|panel]] executed a real remote start on the live charger. The remaining allowlist entry is safe to delete; `app-remote` only functions in zero-user bootstrap mode. The original UI wishlist, all since delivered by the panel: A mobile-friendly web control panel (no app store): diff --git a/wiki/entities/backend.md b/wiki/entities/backend.md index 97e2a12..4cae0e2 100644 --- a/wiki/entities/backend.md +++ b/wiki/entities/backend.md @@ -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::`, `relay:`, `admin` — full model in [[authorization]]. Stdlib crypto only (PBKDF2 + HMAC sessions). Zero users = open API (startup warns); bootstrap via `python -m backend.users add --scopes admin`. - Remote starts run under the calling user's own idTag (`app-`) → 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 " entries are auto-dropped on startup), and the charger-side gate enforces the user's `charger::` 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). diff --git a/wiki/entities/frontend.md b/wiki/entities/frontend.md index 4c28429..2995270 100644 --- a/wiki/entities/frontend.md +++ b/wiki/entities/frontend.md @@ -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 | diff --git a/wiki/log.md b/wiki/log.md index 4c6fa24..84ccb4c 100644 --- a/wiki/log.md +++ b/wiki/log.md @@ -99,3 +99,7 @@ Owner wants meter values visible per gun in Control. Backend: latest Sample.Peri ## [2026-07-12] meta | User app idTags no longer pollute the allowlist Owner: "why do we need this app token of X? We just need the user." Agreed — decide() now validates a user's app idTag directly against the user record (and enforces their charger:: scopes at the charger-side gate too); charger_start no longer auto-enrolls; enrolling a user's tag via the allowlist API returns 400; existing "app token of " entries are auto-dropped at startup. Open-mode bootstrap: "app-remote" authorizes with zero users configured. Session method audit: user tags -> "app". Smoke: 63 checks. Updated [[backend]], [[authorization]]. + +## [2026-07-12] lint | Session wrap-up: milestones + gaps from today filed + +Owner asked whether the wiki needs updating — it did. Filed: panel verified end-to-end on the phone incl. a real in-app start on the live charger (tx 1-2, 141 Wh, who=julian/method=app; the two pre-refactor session rows' who labels were repaired in the db); six household users created; "app-remote" retired (delete from Cards when convenient); Ctrl+C shutdown fix (timeout_graceful_shutdown=3 vs the never-closing charger socket); SPA cache headers + the ":9000 serves the last build" rule; telemetry columns (V/A/context) + live telemetry on /api/status; battery gauge in Control. Refreshed [[overview]] (milestones + trimmed next steps: Tuya keys, remote-stop question, deploy as service), [[backend]], [[frontend]], [[authorization]]. diff --git a/wiki/overview.md b/wiki/overview.md index a498067..ac38c92 100644 --- a/wiki/overview.md +++ b/wiki/overview.md @@ -1,6 +1,6 @@ --- type: meta -updated: 2026-07-11 +updated: 2026-07-12 tags: [synthesis] --- @@ -23,14 +23,18 @@ tags: [synthesis] Hardware surprise: this is a **DC-capable multi-standard charger** (gun 1 EU, gun 2 Chinese GB/T @ 30 kW), not the assumed basic AC unit — see [[anfu-charger]]. +## Milestones reached (2026-07-12) + +- ✅ Live cutover: `eu092025` connects to `python -m backend.main` (2026-07-11 evening) +- ✅ **The panel works end-to-end on the owner's phone**: login, and a real in-app remote start on gun 1 of the live charger (2026-07-12 morning, tx 1–2, 141 Wh, attributed who=julian / method=app) +- ✅ Six household users created (admin + scoped members) + ## What's next -1. ~~Cut the live charger over to the backend~~ — ✅ done 2026-07-11 evening: `eu092025` connects to `python -m backend.main` (verified in events.jsonl). Remaining: a card tap + a panel button-push on the live charger. -2. **Create the real users** — `python -m backend.users add --scopes ...` for each household member (the API stays open until the first user exists). -3. **Extract the Tuya local keys** (`tinytuya wizard` — steps in [[wifi-relays]]) and register them via `PUT /api/relays/` → relays become controllable. -4. **Restart the backend once** to pick up the React panel + pending-card workflow (state changes never need restarts; code updates do). -5. **Test the panel from a phone** — `http://:9000/`; verify login, a real button-push start on a ready gun, the pending-card banner (tap an unenrolled card), and add-to-home-screen over [[netbird|NetBird]]. -6. **Resolve the ❓ remote-stop restart question** — did the gun-2 session auto-restart from auth cache after RemoteStop, or was the card re-tapped? Affects the app's Stop button UX ([[authorization]]). +1. **Extract the Tuya local keys** (`tinytuya wizard` — steps in [[wifi-relays]]) and register them via `PUT /api/relays/` → relays become controllable. +2. **Resolve the ❓ remote-stop restart question** — did the gun-2 session auto-restart from auth cache after RemoteStop, or was the card re-tapped? Affects the app's Stop button UX ([[authorization]]). Test: remote-stop, touch nothing for 5 min. +3. **Deploy as an always-on service** ([[architecture-plan]] phase 4) — decide the host (❓ below), run under NSSM/systemd, DHCP reservation. +4. Housekeeping: delete the retired `app-remote` allowlist entry from the Cards page; tap the remaining household cards so they pend and can be linked to their owners. ## Open decisions ❓