Files
refusol-datalogging/poller/ONSITE_AGENT_BRIEF.md
T
bonaminandClaude Opus 5.5 0b0e4b7d6d docs(poller): test the endpoint with a real inverter id, not TEST
Any id posted becomes a permanent inverter card, and there's no delete yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 09:02:22 +03:00

3.4 KiB

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

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

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