From 3694cdf207f82e008ecec119a596c1ecfbcc98bc Mon Sep 17 00:00:00 2001 From: Thomas Karner Date: Sun, 20 Sep 2026 23:26:51 +0200 Subject: [PATCH] dev: re-create TODO.md; Dockerization in mind but postponed --- TODO.md | 214 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100644 TODO.md diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..a3a68be --- /dev/null +++ b/TODO.md @@ -0,0 +1,214 @@ +# TODO: poorBird + +**Baseline:** [SPEC.md](SPEC.md) · **Device contract:** [firmware/API.md](firmware/API.md) · **Hardware notes:** [firmware/README.md](firmware/README.md) +**Updated:** 2026-09-20 + +This file tracks *work*. It does not restate decisions — those live in SPEC §0. +Anything here that contradicts SPEC means SPEC needs an edit, not a workaround. + +--- + +## Decisions since SPEC §0 + +| Decision | Consequence | +|---|---| +| **Deploy natively, not with Docker** | SPEC §6's *Deploy* row is void; the stack itself is unchanged (FastAPI + PostgreSQL 17 + React/TS). It runs as systemd units from a venv, with Caddy and Postgres as host packages. `TODO.Dockerization.md` is deleted — the content was obsolete, not the idea. | +| **Build container-ready anyway** | Containers stay a plausible future, so the design avoids anything that would make the move expensive. Constraints listed under Phase 1.2. They cost close to nothing and most are better practice natively too. | +| **Server = x86 thin client, Linux, same LAN** | Closes SPEC §10 Q5. amd64 matches the dev machine, so no cross-building. Native NVMe/SATA, no SD-card corruption failure mode. Detection (Option C) stays physically possible. | +| **The server owns everything non-device** | Database, WebUI, image store, auth, backup, OTA hosting, stream sink. The ESP side only ever needs one IP and port. | + +- [ ] Fold these three rows into SPEC §0 and strike the *Deploy* row of §6 — **do this first**, so SPEC stays the single baseline + +--- + +## Where things actually stand + +| Area | State | +|---|---| +| Firmware | Written, compiles, **never run on hardware**. Known gaps below. | +| Device↔server contract | Specified in full (`firmware/API.md`). Nothing implements the server half. | +| Data model | Designed (SPEC §3) + §0 additions. No migration written. | +| Server | **Nothing exists.** | +| WebUI | **Nothing exists.** | + +--- + +## Phase 0 — Hardware bring-up (blocks everything) + +The riskiest unknowns in this project are physical, not architectural. None of the +server work is wasted if this goes badly, but all of it is pointless until it goes well. + +### 0.1 Before anything is connected + +- [ ] **Measure the LD2410's TX logic level on a 5 V supply.** Unverified on this hardware + (`firmware/README.md` → Wiring). A 5 V swing into the ESP32S3 RX damages the pin. + Level-shift or divide if it is not 3.3 V. +- [ ] Verify `PIN_STATUS_LED` (GPIO21) against the actual XIAO board revision — it has moved between revisions +- [ ] Bench-power the board and confirm the mains supply holds up under WiFi TX + camera peaks + +### 0.2 First flash + +- [ ] Fill `secrets.ini` from `secrets.ini.example`, flash with the OTA partition table (`partitions/poorbird_8mb_ota.csv`) +- [ ] Confirm PSRAM is detected and the frame ring allocates at the configured depth +- [ ] Confirm camera init + the day profile produce a sane JPEG over serial/local dump +- [ ] Confirm SNTP sync, and that the device falls back to `server_time` cleanly when SNTP fails + +### 0.3 Radar — the biggest unknown in the project + +SPEC §10 Q3, restated as a radar question. Everything downstream assumes this works. + +- [ ] Verify `ld2410.cpp` frame offsets against real module output — they are from the datasheet, not measured +- [ ] Verify baud autodetection across all three cases: factory default (256000), reconfigured (115200), factory-reset +- [ ] Make `radarSetGateSensitivity` validate that the ACK *matches*, not merely that bytes came back +- [ ] **Tune gates for birds at the real feeder distance.** Log distance + per-gate energy for a full day, then set thresholds from the data rather than from defaults +- [ ] Decide the fallback if radar cannot be tuned acceptably: AM312 PIR on `PIN_AUX_ADC` (one function, `radarIsTrigger`), or on-device frame differencing + +### 0.4 Known code defects + +- [ ] `nightlight.cpp` allocates an LEDC channel after the camera has claimed channel 0 for XCLK — routes around it in theory, untested in practice +- [ ] Battery percentage curves are generic room-temperature open-circuit approximations. Fine for the low banner and the OTA gate; do not present as a runtime estimate +- [ ] Enclosure: IP65, sun shade, drainage, desiccant. Condensation ruins more photos than any software bug + +--- + +## Phase 1 — Server foundation + +Target host: the x86 Linux thin client. No containers — packages and systemd units. + +- [ ] Base install: static IP (or DHCP reservation) and **hardcode that address in firmware** — more reliable than mDNS +- [ ] PostgreSQL 17 from the distro or PGDG repo; dedicated role + database; **loopback TCP with `scram-sha-256`, not a Unix socket** (see 1.2) +- [ ] Python 3.13 venv under `/opt/poorbird`, FastAPI + Pydantic v2 + SQLAlchemy 2.0 + Alembic +- [ ] systemd units: `poorbird-api.service`, `poorbird-worker.service`, both `After=postgresql.service` with restart policies +- [ ] Caddy as a host package; automatic TLS via **DNS-01** so a LAN-only hostname gets a valid cert with no port forwarding +- [ ] Tailscale for remote access +- [ ] Image store at `/srv/poorbird/images/YYYY/MM/DD/.jpg`, thumbs alongside as `_400.webp` (SPEC §3.3) +- [ ] journald log retention capped, disk usage alarmed + +### 1.1 Schema — SPEC §3 plus the §0 additions + +- [ ] Initial Alembic migration covering SPEC §3 verbatim +- [ ] `captures.pre_trigger BOOL` — was this frame captured *before* the trigger fired +- [ ] `devices.awake BOOL` — reported every heartbeat, so the UI can show command latency honestly +- [ ] `devices.reenroll_secret_hash` +- [ ] `device_status` time-series table (full column list in SPEC §0) +- [ ] `devices` settings surface: `cam_day`, `cam_night` (full OV2640 parameter sets), night window + behaviour, nightlight mode + brightness, battery calibration, `config_version` +- [ ] Job queue on Postgres with `FOR UPDATE SKIP LOCKED` — thumbnails, retention, backup, exports. **No Redis.** + +### 1.2 Staying container-ready + +Not building containers now. Just not painting into a corner. Each of these is +cheap today and most are the better native choice regardless. + +- [ ] **All config from environment**, via systemd `EnvironmentFile=/etc/poorbird/poorbird.env`. No paths, hosts or secrets baked into code or committed config. That file becomes a compose `.env` unchanged. +- [ ] **Postgres over loopback TCP**, not a Unix socket — the one genuinely container-hostile choice, and the only real change from a purely native design +- [ ] **All mutable state in a few explicit top-level directories** (`/srv/poorbird/images`, `/srv/poorbird/thumbs`, `/var/lib/poorbird`), never scattered under the app dir. These are the future volume mounts. +- [ ] **Log to stdout/stderr.** journald catches it now, a log driver would catch it later. Simpler than app-managed log files either way. +- [ ] **Migrations as a standalone idempotent command** (`alembic upgrade head`), run from `ExecStartPre` — never at app import time +- [ ] **One env var for the image root**, read by both the app and the Caddy config, since the auth-checked handoff needs them to agree on the path +- [ ] **Scheduled jobs run in the worker, not as systemd timers** — decided. APScheduler with a SQLAlchemy jobstore on the existing Postgres. Not primarily for portability: SPEC §3.4 makes *backup schedule + target* and *retention policy* UI-editable server settings, and a UI-editable systemd timer means the app writing unit files and calling `daemon-reload` behind a polkit or sudoers rule. In-app, the schedule is just a settings row. Timers stay the better answer for anything that is **not** UI-configurable — if such a job appears, use one. +- [ ] Keep API and worker as separate processes — already the plan, and it maps 1:1 to two services later + +**Deliberately not doing now:** writing Dockerfiles or a compose file speculatively. That means maintaining two deployment paths to prove a point. + +--- + +## Phase 2 — Walking skeleton: radar → photo → gallery + +The first milestone worth celebrating. Nothing below this line matters until a real +bird photo appears in a browser. + +- [ ] `POST /api/v1/enroll` — bootstrap secret in, per-device `reenroll_secret` + token out. + **Re-enrolling a known `device_uid` must return the existing row with a fresh token, never a duplicate.** +- [ ] `POST /api/v1/ingest` — multipart image + JSON meta, honour `X-Pre-Trigger`, dedupe on sha256 +- [ ] `POST /api/v1/heartbeat` and `POST /status` — full conditions report into `device_status` +- [ ] `GET /api/v1/config` — enums by name not number, `config_version` bump semantics +- [ ] Response envelope + `server_time` in **every** response (SPEC C7: `received_at` stays authoritative) +- [ ] Thumbnail job on ingest +- [ ] Minimal gallery page, no auth yet, purely to prove the path +- [ ] **End-to-end test on real hardware:** bird walks past → burst uploads → visible in browser + +--- + +## Phase 3 — WebUI + +- [ ] React + TS + Vite + TanStack Query/Router, built on the dev machine, served as static files by Caddy +- [ ] Virtualised gallery grid; filters for date range, taxon, device, tag, reviewed, kept +- [ ] Observation editor — `captures` 1—n `observations`, so a photo can hold two species or none +- [ ] Taxon autocomplete; seed `taxa` with 60–80 Central European garden species incl. GBIF keys, `name_de` + `name_en`, `is_local_common` ranking first +- [ ] Tags, favourite/reject (`kept`), review flag +- [ ] Three themes — light, dark, blue — as design tokens → CSS custom properties, persisted per user +- [ ] Auth: session cookies, Argon2id, CSRF, RBAC per SPEC §3.1 (viewer / editor / admin), `audit_log` on every mutation +- [ ] **Auth-checked image serving** — the app authorizes, Caddy serves the bytes. An unguessable URL is not access control +- [ ] Optional TOTP 2FA (see open Q14) + +### 3.1 Two things the UI must not get wrong + +- [ ] `battery_valid = false` means **not measured** (no divider is wired by default) — render as "n/a", never as a flat-battery alarm +- [ ] Daily counters live in RTC memory and reset on power loss. The `captures` table is authoritative; the counters' value is the **gap** between captured and delivered, which is an upload-health signal + +--- + +## Phase 4 — Device management & OTA + +- [ ] Device list with live/awake state, last seen, RSSI, heap/PSRAM, ring depth +- [ ] Settings editor writing the `devices` settings surface → `apply_config` → `config_version` +- [ ] Command queue UI: `wake_and_hold`, `capture_now`, `apply_config`, `ota_update`, `stream_start`, `reboot`; commands ride along on the ingest response +- [ ] Firmware upload, SHA-256, target marking, per-device staged rollout +- [ ] Verify the full OTA path on hardware: **trial boot and automatic rollback**. The camera is unreachable once mounted — this is the one feature with no recovery if it is broken +- [ ] Document that rotating the shared bootstrap secret server-side without shipping new firmware **removes the last-resort escape hatch** + +--- + +## Phase 5 — Operations + +- [ ] restic → NAS. **Decide the NAS protocol first (open Q9)** — SFTP or a mounted path; SMB-only changes the tooling +- [ ] `pg_dump` pre-hook; retention 7 daily / 4 weekly / 12 monthly +- [ ] **Monthly automated restore test** into a scratch Postgres database on the same host (the Docker-based scratch container from SPEC §6 is replaced by a throwaway cluster/DB). A backup you have never restored is a hypothesis. +- [ ] Alarms via ntfy or Gotify + WebUI banner: low battery, device offline > N hours, disk > 80 %, backup failure, ingest stalled +- [ ] Retention policy job (open Q8 — and decide whether deleting in the UI deletes the file or only hides it) +- [ ] `GET /api/v1/health` covering device liveness, battery, disk, last backup + +--- + +## Phase 6 — Streaming (plumbing only) + +Scope is device → server, watched internally. Public relay stays out (SPEC C3). + +- [ ] Chunked MJPEG sink per `firmware/API.md` → Streaming +- [ ] `record` / `watch` / `both` modes; the record writer plus the ingest writer are the two concurrent writers that justified Postgres +- [ ] Session time-box: 60 s default, firmware-capped at 600 s. Kept as policy, not as a power constraint +- [ ] Live view in the WebUI, admin-only + +--- + +## Explicitly not now + +- **Species detection** — schema is ready (`observations.source`, `model_version`, `confidence`, `bbox`), pipeline is not built. Revisit after a few thousand real captures, when you also know whether you want to label them. +- **Public stream / public gallery** — SPEC Option C. +- **Local SD buffering** of failed uploads — pins are free; add only if the WiFi link proves marginal. +- **On-device frame differencing** — the PSRAM ring makes this easy to add later. +- **TLS on the device** — deliberate, SPEC C2. +- **Containers** — not now, but the door stays open; see Phase 1.2. **Kubernetes** stays shut regardless: a control plane on a single host gains nothing here. +- **Audio / BirdNET** — different sensor, different pipeline. + +--- + +## Still open (from SPEC §10) + +Answered and closed: Q1 (Option B), Q2 (XIAO ESP32S3 Sense), Q4 (internal first), Q5 (x86 thin client). +Void under mains power: Q10 (battery chemistry). + +| # | Question | Blocks | +|---|---|---| +| 3 | Does the radar trigger reliably on *your* birds, at *your* distance? | Phase 0.3 — the project's biggest unknown | +| 9 | NAS access protocol — SFTP, SMB, NFS? | Phase 5, backup tooling choice | +| 6 | How many cameras eventually? | Phase 4 scope (device management, OTA staging) | +| 7 | Expected captures per day? | Storage sizing, retention, inline-vs-queued thumbnailing | +| 8 | Retention policy, and does UI delete remove the file? | Phase 5 | +| 11 | UI language — German, English, or both? | Cheap on day one, annoying to retrofit. `name_de`/`name_en` exist either way | +| 12 | Taxonomy source — GBIF backbone, IOC, Avibase? Which regional seed list? | Phase 3 taxa seed | +| 13 | The "blue" theme — a reference palette, or my choice? | Phase 3 theming | +| 14 | Is 2FA required, or is a strong password on a LAN-only service enough? | Phase 3 auth | +| 15 | Anything to record beyond SPEC §3 — weather, feeder type, ring number? | Schema, cheapest to settle before the first migration | +| 16 | Comfort level in C / Python / TypeScript? | The React frontend is the largest chunk of potentially unfamiliar work | +| 17 | Can the camera see a neighbour's garden or a public path? | One GDPR paragraph in the deployment notes |