P06D is a latched 21450 (not power), P052/P05A static, P063 frozen; power is computed V*I. Lists what's sent, what isn't, the unmapped diagnostics, the INV1-INV5 IP assignments, and that timestamps must be real UTC. The simulator now sends the same payload shape. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
75 lines
3.4 KiB
Markdown
75 lines
3.4 KiB
Markdown
# 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 the current
|
|
state of the register map (what's verified, what isn't sent yet).
|
|
|
|
## 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 in `README.md`.
|
|
Leave out anything you couldn't read or haven't verified; every field is
|
|
optional. Timestamps must be real UTC (see README).
|
|
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":"INV1","ac_power_total_w":1234}]'
|
|
# use a real inverter id: every id sent shows up as an inverter on the dashboard
|
|
# -> {"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
|