Files
charging_station/wiki/overview.md
T
julian 56c9020d9f refactor(backend): single SQLite store — config.json eliminated
backend.db (renamed from sessions.db) now holds everything: the sessions
and samples tables plus a settings table with the app-state sections
(users, allowlist, relays, chargers, learn_mode, session_secret) as JSON
blobs. All mutations go through the API/panel and take effect immediately;
there is no config file and no hand-edit-then-restart ambiguity.

- legacy config.json auto-imports into the db on first start (renamed to
  config.json.migrated as a backup)
- new admin endpoints: PUT/DELETE /api/relays/{name} (how tinytuya wizard
  results are registered now) and PUT /api/chargers/{cp_id} (panel labels)
- BACKEND_DB env override so tests run on an isolated temp database
- smoke test: 45 checks, real db verified untouched
2026-07-11 20:15:38 +02:00

47 lines
5.1 KiB
Markdown

---
type: meta
updated: 2026-07-11
tags: [synthesis]
---
# Overview — Anfu Home Charger OCPP Project
**Goal:** a private, self-hosted [[ocpp|OCPP 1.6J]] backend (CSMS) for a home EV charger. No billing, no public charging. Authorization via existing RFID cards ✅ and a mobile-friendly web app reached over [[netbird|NetBird]] (by-vehicle ❌ closed — firmware never forwards a vehicle id). **Scope expanded 2026-07-11:** the same backend also controls the household [[wifi-relays|Tuya/SmartLife WiFi relays]], locally via tinytuya.
## Current state (2026-07-11)
**Connectivity: ✅ solved.** The [[jc-6620|JC-6620]] controller inside the [[anfu-charger|charging pile]] reliably dials out to the CSMS — verified both on the charger's own LAN (`192.168.2.114:9000`) and across the NAT boundary on the WAN subnet (`10.0.10.203:9000`). Getting here required the fixes catalogued in [[troubleshooting]]; the network layout is in [[network-topology]].
**Software: production [[backend]] built (2026-07-11), including the web panel.** `station.py` was ported into the `../backend/` package: one FastAPI process on port 9000 = CSMS WebSocket + `/api/*` (charger control, allowlist CRUD, runtime learn-mode flip) + [[wifi-relays|Tuya relay]] on/off/toggle + **multi-user auth** (username/password, per-resource scopes: gun 1 / gun 2 / per-relay / admin, per-gun-restrictable RFID cards — [[authorization]]) + **consumption tracking** (SQLite: who charged, when, how many kWh, per-minute meter samples) + the **PWA control panel** at `/` (login, scope-filtered start/stop buttons, relay toggles, history, admin). Smoke-tested (45 checks incl. a fake charge point over the real WS route); ✅ live charger connects to it since 2026-07-11 evening; ⚠️ panel untested from a real phone. All state lives in one SQLite file (`backend.db`) — no config file, every change via API/panel takes effect immediately. The [[csms-toolkit]] (`../discovering/`) remains as diagnostic tooling.
**Capabilities: ✅ known.** The live probe ([[2026-07-09-discovery-eu092025]]) identified the pile as SimpleCharge "MultiSocketCharger" (fw 1.24.0620.1, OCPP ID `eu092025`) with **two guns**, RemoteTrigger (verified), SmartCharging, Reservation, a 6-entry local auth list, and per-minute meter data including SoC. Only Autocharge remains unknown (physical test pending; `MacEnabled` is a lead — [[authorization]]).
**Authorization: 2 of 3 methods ✅ verified live (2026-07-09 test session, both cars plugged, both guns charging simultaneously):**
- **RFID** ✅ — card `…393` tapped → Authorize → real charging session on gun 2 (DC, ~26 kW avg, 1.8 kWh delivered). Card enrolled as "RFID card A".
- **Remote (app path)** ✅ — RemoteStart and RemoteStop both Accepted and executed on gun 1; `app-remote` token enrolled.
- **By vehicle** ❌ **closed** — three escalating tests (plain plug-in, `MacEnabled=true` live, `MacEnabled=true` after power-cycle) all negative; this firmware never forwards a vehicle ID over OCPP ([[authorization]]).
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]].
## 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 <name> --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/<name>` → relays become controllable.
4. **Flip learn mode off** — both cards + the app token are enrolled; switchable from the panel's Admin tab or `POST /api/mode?learn=false`, no restart. (Only wait if more cards need tapping.)
5. **Test the panel from a phone** — it's built and serving at `http://<host>:9000/`; verify login, a real button-push start on a ready gun, 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]]).
## Open decisions ❓
| Decision | Options | Status |
|---|---|---|
| Always-on host for CSMS + app | LAN PC · the `10.0.10.203` machine · dedicated box (e.g. Pi on charger LAN, joined to NetBird) | open — now also needs subnet reachability to the [[wifi-relays|relays]] for local Tuya control |
| Web app auth | — | ✅ **resolved 2026-07-11**: username+password login with per-resource scopes (gun 1 / gun 2 / per-relay / admin) — see [[authorization]]. Bootstrap: create the first admin user via `python -m backend.users add` |
| Autocharge / by vehicle | — | ❌ **closed 2026-07-09**: not supported by this firmware ([[authorization]]) |
| Host IP stability | static IP · DHCP reservation | open (required either way — touchscreen URL is hardcoded) |
## Sources
- [[2026-07-09-findings-and-requirements]] — the founding findings/requirements doc