docs(poller): brief for the agent building the on-site poller

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-21 09:02:12 +03:00
co-authored by Claude Opus 5.5
parent b5c7663fd7
commit 9d41c77668
+72
View File
@@ -0,0 +1,72 @@
# Brief: sending inverter readings to the Solar Monitor backend
You are building (or updating) the script on the site laptop that reads the
Refusol 020K inverters over USS/TCP and reports to the backend. The backend
and dashboard already run at **https://solar.bonamin.net**. Your job is only
the on-site side: read the inverters, POST the values.
## Files to use
- `backend_client.py` (next to this brief): copy it next to your script and
use it to send. It's standard library only. It timestamps readings, keeps
them in `unsent_readings.jsonl` when the internet is down, re-sends them
later, and never raises.
- `README.md` (next to this brief): the field names, units and scalings.
## What to do every 60 s
```python
from backend_client import BackendClient
BACKEND_URL = "https://solar.bonamin.net"
API_KEY = "<ask the owner; same value as API_KEY in the server's .env>"
backend = BackendClient(BACKEND_URL, API_KEY)
while True:
readings = []
for inv in INVERTERS: # e.g. [{"id": "INV1", "host": "192.168.1.51"}, ...]
try:
values = read_inverter(inv) # your USS code -> dict of converted values
readings.append({"inverter_id": inv["id"], **values})
except Exception as e:
log.warning("%s not answering: %s", inv["id"], e)
# just leave it out: the dashboard marks it Offline (by day) or Sleeping (at night)
backend.send(readings) # ALWAYS call it, even with an empty list
sleep_until_next_minute()
```
## Rules that matter
1. **Always call `send()`, even with an empty list.** The empty list is the
heartbeat. It's how the dashboard tells "inverter dead" (laptop still
reporting) apart from "site/internet down".
2. **`inverter_id` must stay the same forever** for each physical inverter,
e.g. `INV1`..`INV5` matching labels on the units. It's the database key.
Pretty names are set later in the dashboard, not here. Allowed characters:
letters, digits, `_ . -`.
3. **Send converted values**, not raw ones, using the keys and scalings in
`README.md` (e.g. `ac_voltage_l1_v` = P050 raw / 40). Leave out anything
you couldn't read; every field is optional.
4. **New or unconfirmed parameters:** send them too, under a descriptive key
(e.g. `p0xx_raw`). The backend stores unknown keys and shows them on the
inverter page under "Other (unmapped)". Tell the owner when a mapping is
confirmed so it gets promoted to a proper field.
5. **Fault status:** if you find the parameter holding the inverter's
state/error code, send it as `status_code` / `error_code` (non-zero
`error_code` = the dashboard shows **Fault**), with an optional
`status_text`. This is high priority: it's the most direct "is it broken?" signal.
6. A failed inverter read must never stop the loop or the other inverters.
7. Run it so it survives reboots: Windows Task Scheduler "at startup" or a
service; systemd on Linux.
## Checking it works
```bash
curl -X POST https://solar.bonamin.net/api/readings \
-H "X-API-Key: <key>" -H "Content-Type: application/json" \
-d '[{"inverter_id":"TEST","ac_power_total_w":1234}]'
# -> {"received":1,"stored":1,"duplicates":0}
```
Then open https://solar.bonamin.net. The inverter appears within 30 s.
API reference: https://solar.bonamin.net/api/docs