docs(wiki): discovery results, architecture, auth model, backend + relay pages

Ingests the 2026-07-09 live session (source page + raw GetConfiguration
dump): charger identified as SimpleCharge MultiSocketCharger, 60 kW DC
dual-standard (gun 1 EU/CCS, gun 2 GB/T); RFID and remote start/stop
verified; by-vehicle auth closed as not supported (three escalating tests
incl. MacEnabled=true after power-cycle); touchscreen-shows-VIN observation
with the DataTransferVendorId long-shot lead.

Adds/updates: architecture plan (FastAPI + PWA, phases 1-3 done), backend
entity, wifi-relays entity (Tuya local-control path + key extraction steps),
authorization concept (API user/scope model, per-gun cards), overview,
runbook, index, log.
This commit is contained in:
2026-07-11 18:58:20 +02:00
parent d7b17d9cb2
commit 3326c8d16c
12 changed files with 713 additions and 31 deletions
+47
View File
@@ -0,0 +1,47 @@
---
type: note
updated: 2026-07-11
tags: [architecture, decision, plan]
---
# Architecture & Build Plan
Filed 2026-07-09 from a stack discussion (Flutter? Fastify vs FastAPI? web frontend?). Extends the requirements in [[2026-07-09-findings-and-requirements]] and the roadmap in [[overview]].
> [!note] Scope expansion (2026-07-11): the backend also controls the household [[wifi-relays|Tuya/SmartLife WiFi relays]] — locally via tinytuya, same process, under `/api/relays/*`. This strengthens the FastAPI/one-process decision: charger + relays + panel behind one NetBird-reachable port.
## Stack decision
**Backend: FastAPI (Python) — decided.**
The deciding constraint: the backend *is* the CSMS. `RemoteStartTransaction`/`RemoteStopTransaction` can only be sent down the live OCPP WebSocket the [[jc-6620|JC-6620]] holds open, so the API server and the OCPP server must share process state. The proven code ([[csms-toolkit]]) is already Python on the `ocpp` library; Fastify would mean rewriting OCPP in Node (immature libraries) or a two-process IPC design. FastAPI hosts everything in one uvicorn process on one port:
```
FastAPI app (uvicorn, :9000, on the always-on host)
├── /<chargePointId> OCPP 1.6J WebSocket (catch-all) ← JC-6620 dials in here
├── /api/* REST: status, charger start/stop, allowlist CRUD, sessions
├── /api/relays/* Tuya relay control (tinytuya, local protocol)
├── /api/events journal tail (SSE live push later, for the panel)
└── / static PWA (the web panel)
```
(The `ocpp` ChargePoint class only needs send/recv; a FastAPI WebSocket route wraps it. Keep port 9000 so the charger touchscreen URL doesn't change — [[troubleshooting]] #4: changing it needs a power-cycle.)
**Web frontend: mobile-first PWA, no build pipeline — decided.**
Plain HTML/JS (Alpine.js or htmx + SSE), served by FastAPI. Features: status card, start/stop, allowlist management, session history. PWA manifest → "add to home screen". Reached only over [[netbird|NetBird]].
**Flutter mobile app: phase 2, optional.**
The PWA covers ~95% of the value. Flutter earns its keep only for push notifications ("charging complete") or as a learning project. It would consume the same REST API (FastAPI's OpenAPI spec → typed Dart client codegen), so nothing built now is wasted. Phone needs the NetBird client either way.
**Storage: SQLite** (single file) for sessions/meter values/seen tags; the allowlist can migrate from `station_config.json` into it once the panel manages it. JSON files were fine for discovery; history queries want a real table. → ✅ implemented 2026-07-11 as `backend/store.py` (`sessions` + `samples` tables); allowlist/users stayed in config.json — right size for a household, revisit only if it grows.
## Build phases
1. **Productionize the CSMS** — ✅ done 2026-07-11 as the [[backend]] package (`../backend/`); SQLite session store added same day (JSONL journal stays as raw ground truth).
2. **REST API** — ✅ done 2026-07-11: status, remote start/stop, allowlist CRUD, runtime learn-mode flip, **relay on/off/toggle**, multi-user login with permission scopes, **session history (who/when/kWh)**. ⚠️ Relay half awaits the [[wifi-relays|local-key extraction]].
3. **Web panel (PWA)** — ✅ built 2026-07-11 (`backend/static/`, vanilla JS instead of Alpine — zero dependencies): login, per-gun status + start/stop gated by scopes and gun readiness, relay toggles, consumption history, admin tab. ⚠️ Untested on a real phone.
4. **Deploy** — pick the always-on host (❓ open, [[overview]]), run as a service (systemd or NSSM on Windows), static IP / DHCP reservation, firewall rule for :9000, joined to NetBird.
5. **Hardware tasks** — RFID enrollment via learn mode; the Autocharge plug-in test ([[authorization]]) to settle "by vehicle".
6. **(Optional) Flutter app** — consumes the same API; adds push notifications.
Phases 1–3 are pure software and can proceed before the host decision; only phase 4 needs it.
+38
View File
@@ -0,0 +1,38 @@
---
type: note
updated: 2026-07-09
tags: [runbook, discovery, hardware-test]
---
# Discovery Test Runbook — Autocharge + RFID Session
> [!note] Executed 2026-07-09 — all tests done, results in [[authorization]] and [[overview]]
> Test A (Autocharge): ❌ negative through all variants incl. `MacEnabled=true` + power-cycle. Test B (RFID): ✅ cards A+B captured & enrolled. Test C (remote start/stop): ✅ both verified. Kept as the template for any future retest (e.g. after a firmware update).
The physical test session to settle the open [[authorization]] questions. Prereq: `station.py` running (`venv\Scripts\python station.py` in `../discovering/`), learn mode ON, charger `eu092025` connected. Watch at `http://10.0.10.203:9000/status`, `/tags`, or `/docs`.
## Order matters
Do the Autocharge test **before** ever tapping a card in this session — the first plug-in is the clean observation.
## Test A — Autocharge (plug in, no card)
Connect a gun to a car. Do not tap anything.
| Observation | Conclusion | Next step |
|---|---|---|
| New idTag in console / `/tags` | ✅ Autocharge works | Let it charge ~2 min (captures first MeterValues/SoC), stop, whitelist the id as `kind:"car"` |
| Connector "Preparing", no idTag | No Autocharge by default | Retry after `POST /setconfig?key=MacEnabled&value=true` (lead from [[2026-07-09-discovery-eu092025]]) |
| Nothing | "By vehicle" not supported | Close the open decision in [[overview]] as ❌ |
## Test B — RFID cards
Tap each owned card once. Each should log `[LEARN] NEW idTag=...` and appear in `/tags`. **Write down the physical tap order** so the ids can be named in the allowlist.
## Test C (optional) — remote start
With a car plugged in: `curl -X POST "http://10.0.10.203:9000/start?connector=1"` — this is exactly what the future web panel will do. Expect `{"remote_start":"Accepted"}` then a `StartTransaction` (note: `AuthorizeRemoteTxRequests=false`, so no separate Authorize).
## Afterwards
Feed results back into the wiki (ingest `seen_tags.json` observations), name cards in `station_config.json` → `authorized`, and once all household ids are enrolled: set `learn_mode: false` and restart — the charger is then enforcing.