Skip to content

fix(solaredge_pv, solaredge_legacy): keep reading the serial after the inverter wakes (1.2.3, 0.3.4) - #298

Merged
frahlg merged 1 commit into
mainfrom
solaredge-serial-retry
Dec 4, 2026
Merged

frahlg merged 1 commit into
mainfrom
solaredge-serial-retry

Conversation

@frahlg

@frahlg frahlg commented Dec 4, 2026

Copy link
Copy Markdown
Member

Problem

solaredge_pv and solaredge_legacy read the SunSpec serial (40052, 16 registers) at the top of driver_poll, before the Model 103 block, through probe_read. That helper gives up on a register after three misses until restart.

SolarEdge inverters often refuse Modbus at night or while another client holds the TCP connection. If FTW Core starts then, the serial uses up its three chances while the inverter answers nothing, and it is never asked again, even after the inverter answers. host.set_sn is never called, the device stays known only by its address, and Core's forecast identity check, which matches the serial in its saved receipt, stays pending. In the field this held back a box's load forecast for 12 hours and kept its load model from learning for a week. AGENTS.md says: report stable hardware identity early.

Core's reload-on-empty-poll does not rescue this: the Model 103 read is not bounded, so every poll attempts a read and the reload never fires.

Change

  • The serial is read last in a poll, and only in a poll whose Model 103 block answered. A sleeping inverter no longer uses up its chances.
  • After three misses on an inverter that does answer, probe_read asks again every five minutes instead of never (RETRY_EVERY_MS, keyed by register, as keba does for its phase currents). Five minutes bounds a serial the inverter keeps refusing to one failed read in sixty polls, and one that answers again still reaches Core within minutes. The first answer reports the serial, clears the count and logs that the register answers again. The MPPT registers keep their give-up until restart.
  • Reading it last means a timeout there cannot start the host's reconnect backoff ahead of the poll's other reads.

How a failed retry reaches Core: Core keeps a poll when at least one read succeeded and none failed at the transport. A refused retry (a Modbus exception) costs nothing. A timeout would cost that one poll, but the retry only runs straight after the Model 103 read succeeded on the same connection, and at most once in five minutes. In the driver the retry cannot change what the poll emits or what it returns.

solaredge_pv 1.2.3 and solaredge_legacy 0.3.4, with manifest changelogs and a CHANGELOG.md entry. solaredge_legacy has the same helper and the same unbounded Model 103 read. Its SunSpec probe at 40000 makes the start-up case rarer there, but a serial that misses three times after that probe was still lost until restart.

Not changed, though they read identity through a give-up helper:

  • sungrow and saj have the same effect with their own counters (sn_tries, three tries until restart, while the main read recovers). sungrow already starts its registers over when the link comes back (settle_poll) but not sn_tries. Each wants its own small change.
  • huawei: only meter power (37113) is unbounded, so after a start-up outage its PV and battery reads give up as well as the serial. That is larger than identity.
  • ctek, ctek_v2, ctek_hybrid, deye, etrel, fronius, keba, kostal, sma, sma_pv, solaredge, solis: every main read goes through the same give-up helper. After an outage from start-up the whole driver stops asking, and Core reloads a driver with nothing left to read only after an earlier read succeeded. Also larger than identity.
  • foxess_h3_smart and solis_string have open PRs on those files.
  • abb_terra and pixii already retry on a timer. goe reads its serial only after its main block answered. mennekes takes it from its required main block.

Evidence

New harness test drivers/tests/lua_harness/test_solaredge_serial_retry.lua, run for both drivers by drivers/tests/test_solaredge_serial_retry.py:

  1. The inverter answers nothing for six polls, then wakes. The first poll after waking reports the serial and emits PV; the serial is not read again.
  2. 40052 fails three times while the Model 103 block answers. No serial read for the next 59 polls (5 s apart). The 60th retries and fails: that poll still returns 5000, emits PV from the block, and its only failed read is the serial. The next retry, with 40052 answering, calls host.set_sn with the serial in the same process; set_sn is called once in all.

Against the drivers on main the test fails (solaredge_pv in case 1, solaredge_legacy in case 2). With this change:

  • make test-driver ID=solaredge_pv: 45 passed, 10 skipped
  • make test-driver ID=solaredge_legacy: 46 passed, 10 skipped
  • make check: 5573 passed, 927 skipped
  • make absent-register-report: 40052 settles (1,1,1,0,0,0,0,0,0,0) in both drivers; every other address reads as on main.

Not tested on hardware. No register, scale or write path changed.

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-04T17:41:01.964713Z a4dfc33 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…e inverter wakes (1.2.3, 0.3.4)

Both drivers read the SunSpec serial (40052) before the Model 103 block,
through a helper that gives up after three misses until restart. An
inverter asleep at start-up, or held by another Modbus client, used up
those three chances while answering nothing. The device then stayed known
only by its address for the life of the process, and Core's forecast
identity check, which matches the serial in its saved receipt, stayed
pending. In the field this held back a load forecast for 12 hours and the
load model for a week.

The serial is now read last in a poll, and only in one whose Model 103
block answered, so a sleeping inverter costs it nothing. After three misses
on an inverter that does answer, it is asked again every five minutes
instead of never: one failed read in sixty polls while it keeps refusing.
The first answer reports it and clears the count. Reading it last means a
timeout there cannot make the host skip the poll's other reads during its
reconnect backoff. No other register's read changed.

A new harness test covers both drivers: an inverter that answers nothing
for six polls and then wakes, and a serial that fails three times while
the inverter answers, fails its first retry and answers its second. Both
old drivers fail it; both new ones pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
@frahlg
frahlg force-pushed the solaredge-serial-retry branch from a4dfc33 to f29d547 Compare December 4, 2026 17:43
@frahlg
frahlg merged commit 5431730 into main Dec 4, 2026
5 checks passed
@frahlg
frahlg deleted the solaredge-serial-retry branch December 4, 2026 17:45
frahlg added a commit to srcfl/ftw that referenced this pull request Dec 4, 2026
…2176)

Moves the pin to srcfl/device-drivers 5eb7189d, which brings:

- ferroamp 2.2.0 (srcfl/device-drivers#299): never sends the EnergyHub a
  setpoint above the limit the hub reports when it refuses one, or above
  ehub_max_w; scales by what the ESOs measurably deliver instead of
  guessing an even split; reports power, SoC and fault code per ESO.
- solaredge_pv 1.2.3 and solaredge_legacy 0.3.4
  (srcfl/device-drivers#298): read the serial only once the inverter
  answers, and ask again every five minutes after three misses, so a
  restart while the inverter sleeps no longer leaves the forecast
  identity pending until the next restart.

Planner PV curtailment accepts only reviewed Ferroamp source hashes.
2.2.0's pplim commands are byte for byte those of 2.1.2, so its hash
joins the list. Two Core tests run the new behaviour under Core's
Lua 5.1: the cap learned from the refusal, and the measured scale with
per-ESO metrics. Both fail on 2.1.2.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant