Files
refusol-datalogging/poller
bonaminandClaude Opus 5.5 d4b584e364 feat: solar inverter monitor — FastAPI + SQLite backend, React PWA dashboard
Monitoring for the Refusol 020K inverters. The on-site poller POSTs each
60 s cycle to /api/readings; the dashboard answers first whether every
inverter is operating and whether one is producing far less than its peers
(string fuse / breaker problems).

- Backend: FastAPI + SQLite. Parameters defined once in fields.py (columns
  auto-added on start); unknown poller keys are kept in `extra` since the
  parameter map is still being researched. Idempotent ingest, daily energy
  rollup in site-local days, history downsampling, 2-year retention.
- Health: Offline vs Sleeping (sun elevation) vs No data (datalogger
  silent, detected via empty-batch heartbeats), Fault from error_code,
  underperformance vs fleet median (per kWp when sizes set), MPPT imbalance.
- Frontend: mobile-first React + Tailwind, installable PWA, comparison bars,
  24 h power / 30 day energy charts, detail page with all parameters.
- Docker: backend + frontend + nginx on one port for NPM, as in
  bellsystems-cp; deploy-host.sh pulls main and rebuilds.
- poller/backend_client.py: stdlib client with offline spool for
  refusol_poller.py; fake_poller.py simulates the site.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 07:42:48 +03:00
..

On-site poller

refusol_poller.py (not in this repo yet) reads the inverters over USS/TCP (port 21062, USS address 0). It sends each cycle to the backend through backend_client.py — copy that file next to the poller.

Wiring it into refusol_poller.py

At the top of the file:

from backend_client import BackendClient

BACKEND_URL = "https://solar.bonamin.net"
API_KEY = "same value as API_KEY in the server's .env"

backend = BackendClient(BACKEND_URL, API_KEY)

At the end of every poll cycle, one dict per inverter that answered:

readings = []
for inverter_id, values in polled.items():      # however the poller holds them
    readings.append({"inverter_id": inverter_id, **values})
backend.send(readings)                          # also call it when the list is empty

Each dict uses the keys below (all optional — send what was read). Anything else you include (e.g. a newly discovered parameter as "p0xx_raw": 1234) is stored too and shows under "Other (unmapped)" on the inverter page.

key unit source
ac_voltage_l1_v / _l2_v / _l3_v V P050 / P05B / P064 raw / 40
dc_voltage_mppt1_v / _mppt2_v V P052 / P054 raw / 40
dc_current_mppt1_a / _mppt2_a A P05A / P05C raw / 10
ac_current_l1_a / _l2_a / _l3_a A P068 / P069 / P06A raw / 100
ac_power_total_w W P06D raw
grid_frequency_hz Hz P06C raw / 20
temperature_c °C P070 raw >> 16
daily_energy_wh Wh P063 IND=0 raw × 10
total_energy_wh Wh P063 IND=11 raw
status_code – inverter state, once identified
error_code – non-zero = fault (shows the inverter as Fault)
status_text – optional human text for the code

send() stamps each reading with the current UTC time, buffers to unsent_readings.jsonl when the internet is down and re-sends later, and never raises — a backend problem can't stop the polling loop.

Call send([]) even when no inverter answered. That's the heartbeat that lets the dashboard say "inverter not responding" (site online) instead of "datalogger offline" (site/internet down).

Trying the dashboard without the site

python fake_poller.py --url http://localhost:8090 --key change-me --backfill-days 30