update README
This commit is contained in:
1 parent
ea11403528
commit
cbd9792d84
1 file changed
+161
-2
@@ -1,3 +1,162 @@
|
||||
# Cultivar-Daemon
|
||||
# Cultivar Daemon
|
||||
|
||||
Linux service for deployment on Cultivar.
|
||||
Linux service for the [Grove5](https://grove5.com) Cultivar appliance.
|
||||
|
||||
**Grove5 — Open source software, honest hardware.**
|
||||
|
||||
---
|
||||
|
||||
## What it does
|
||||
|
||||
The daemon runs on the QRB2210 Linux side of the Arduino UNO Q. It reads raw environmental payloads from two STM32-driven ENV-1 sensor boards over serial, processes them, stores everything in SQLite, and serves real-time data to the Cultivar UI via WebSocket and REST.
|
||||
|
||||
```
|
||||
STM32 (colonization) → /dev/ttyS0 ─┐
|
||||
├→ processor → SQLite → WebSocket → UI
|
||||
STM32 (fruiting) → /dev/ttyS1 ─┘
|
||||
```
|
||||
|
||||
## Architecture
|
||||
|
||||
```
|
||||
cultivar_daemon.py main entrypoint — wires everything together
|
||||
serial_reader.py reads STM32 JSON payloads over serial
|
||||
processor.py humidity correction, normalization, CO2e, anomalies
|
||||
storage.py SQLite persistence
|
||||
api.py FastAPI — REST + WebSocket + serves Svelte UI
|
||||
schema.sql SQLite schema
|
||||
cultivar_types.py Pydantic models (symlinked from cultivar-types)
|
||||
```
|
||||
|
||||
## Sensor pipeline
|
||||
|
||||
Each collection cycle (~5 minutes) per chamber:
|
||||
|
||||
1. **STM32** collects ambient reading (BME690 heater off) + 10-point gas sweep
|
||||
2. **Serial reader** validates JSON against `STM32Payload` Pydantic model
|
||||
3. **Processor** applies humidity correction, baseline normalization, zone scoring, CO2e estimation, anomaly detection
|
||||
4. **Storage** persists raw JSON + all derived values to SQLite
|
||||
5. **WebSocket** broadcasts `EnvPayload` to connected Svelte UI clients
|
||||
|
||||
## Gas sweep zones
|
||||
|
||||
| Zone | Temps | Target |
|
||||
|------|-------|--------|
|
||||
| 1 — Baseline | 200, 220, 250°C | Humidity/CO2 proxy |
|
||||
| 2 — Biological | 280, 300, 320, 340°C | Mycelium activity, contamination |
|
||||
| 3 — Heavy | 360, 380, 400°C | Ammonia, sulfur, heavy VOCs |
|
||||
|
||||
## Setup
|
||||
|
||||
### Dependencies
|
||||
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
# On UNO Q Debian:
|
||||
pip install -r requirements.txt --break-system-packages
|
||||
```
|
||||
|
||||
### Shared types
|
||||
|
||||
```bash
|
||||
ln -s ../cultivar-types/python/cultivar_types.py cultivar_types.py
|
||||
```
|
||||
|
||||
### Run
|
||||
|
||||
```bash
|
||||
# Production (both chambers)
|
||||
python cultivar_daemon.py
|
||||
|
||||
# Single chamber dev
|
||||
ENABLE_FRUITING=false python cultivar_daemon.py
|
||||
|
||||
# Replay mode — no hardware needed
|
||||
REPLAY_MODE=true \
|
||||
ENABLE_FRUITING=false \
|
||||
REPLAY_COLONIZATION=samples/colonization.jsonl \
|
||||
python cultivar_daemon.py
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
All config via environment variables:
|
||||
|
||||
| Variable | Default | Description |
|
||||
|----------|---------|-------------|
|
||||
| `COLONIZATION_PORT` | `/dev/ttyS0` | Serial port for colonization ENV-1 |
|
||||
| `FRUITING_PORT` | `/dev/ttyS1` | Serial port for fruiting ENV-1 |
|
||||
| `SERIAL_BAUD` | `115200` | Serial baud rate |
|
||||
| `ENABLE_COLONIZATION` | `true` | Enable colonization chamber |
|
||||
| `ENABLE_FRUITING` | `true` | Enable fruiting chamber |
|
||||
| `REPLAY_MODE` | `false` | Replay from .jsonl files |
|
||||
| `REPLAY_COLONIZATION` | `samples/colonization.jsonl` | Replay file path |
|
||||
| `REPLAY_FRUITING` | `samples/fruiting.jsonl` | Replay file path |
|
||||
| `REPLAY_DELAY` | `5.0` | Seconds between replayed payloads |
|
||||
| `API_HOST` | `0.0.0.0` | FastAPI host |
|
||||
| `API_PORT` | `8000` | FastAPI port |
|
||||
| `DB_PATH` | `cultivar.db` | SQLite database path |
|
||||
| `BASELINE_MIN_SAMPLES` | `6` | Samples before baseline established |
|
||||
| `BASELINE_HUM_VARIANCE` | `5.0` | Max %RH variance for baseline gate |
|
||||
| `HEARTBEAT_INTERVAL` | `30` | WebSocket heartbeat interval (s) |
|
||||
|
||||
## API
|
||||
|
||||
Interactive docs at `http://localhost:8000/docs` when running.
|
||||
|
||||
| Endpoint | Description |
|
||||
|----------|-------------|
|
||||
| `GET /api/health` | Daemon status |
|
||||
| `GET /api/environment/{chamber}/history?hours=24` | Environment history |
|
||||
| `GET /api/environment/{chamber}/latest` | Most recent payload |
|
||||
| `GET /api/environment/{chamber}/sweep?hours=24` | Gas sweep history |
|
||||
| `GET /api/anomalies/{chamber}` | Active anomalies |
|
||||
| `POST /api/anomalies/{id}/dismiss` | Dismiss anomaly |
|
||||
| `GET /api/baseline/{chamber}` | Active baseline |
|
||||
| `POST /api/baseline/{chamber}/reset` | Reset baseline |
|
||||
| `POST /api/runs` | Start cultivation run |
|
||||
| `GET /api/runs/{chamber}/active` | Active run |
|
||||
| `POST /api/runs/{id}/end` | End run |
|
||||
| `PATCH /api/runs/{id}` | Update run metadata |
|
||||
| `WS /ws` | Real-time payload stream |
|
||||
|
||||
## WebSocket messages
|
||||
|
||||
```json
|
||||
{"type": "payload", "chamber_id": "fruiting", "data": {...}}
|
||||
{"type": "anomaly", "chamber_id": "colonization", "data": {...}}
|
||||
{"type": "baseline", "chamber_id": "colonization", "data": {...}}
|
||||
{"type": "heartbeat", "chamber_id": null, "data": null}
|
||||
```
|
||||
|
||||
## Database
|
||||
|
||||
SQLite at `cultivar.db`. Schema in `schema.sql`. Tables:
|
||||
|
||||
- `runs` — cultivation lifecycle per chamber
|
||||
- `payloads` — one row per collection cycle, raw JSON preserved
|
||||
- `sweep_points` — normalized 10-point gas sweep data
|
||||
- `baselines` — per-run baseline resistance fingerprints
|
||||
- `anomalies` — detected events with contaminant hints
|
||||
- `co2e_calibration` — paired (SCD43, sweep) training data for CO2e model
|
||||
|
||||
## Hardware
|
||||
|
||||
**ENV-1-V0.1** sensor board, two population variants:
|
||||
|
||||
| Variant | Sensors | Chamber |
|
||||
|---------|---------|---------|
|
||||
| Full | BME690 + SCD43 | Fruiting |
|
||||
| Lite | BME690 only | Colonization |
|
||||
|
||||
Chamber identity is self-declared by the firmware: if SCD43 is not populated, the board identifies itself as `colonization`.
|
||||
|
||||
## Related repos
|
||||
|
||||
- [`grove5/cultivar-firmware`](https://gitea.hillernet.com/grove5/cultivar-firmware) — STM32 Arduino library + sketch
|
||||
- [`grove5/cultivar-types`](https://gitea.hillernet.com/grove5/cultivar-types) — shared TypeScript + Python types
|
||||
- [`grove5/cultivar-ui`](https://gitea.hillernet.com/grove5/cultivar-ui) — Svelte frontend
|
||||
|
||||
## License
|
||||
|
||||
MIT — Grove5
|
||||
Reference in new issue
Block a user