Skip to content

fix(fronius_smart_meter): read the Smart Meter again after a silent start (2.1.4) - #329

Open
frahlg wants to merge 1 commit into
mainfrom
fix/fronius_smart_meter-wake
Open

frahlg wants to merge 1 commit into
mainfrom
fix/fronius_smart_meter-wake

Conversation

@frahlg

@frahlg frahlg commented Dec 5, 2026

Copy link
Copy Markdown
Member

Problem

fronius_smart_meter 2.1.3 read every float through read_f32 and probe_read, which leaves a register alone until restart after three misses. A Smart Meter that was off, restarting or held by another Modbus client when FTW started used up every try while answering nothing. The driver then sent nothing until FTW restarted it.

Two smaller faults sat in the same decoder:

  • A float that held NaN or infinity, the SunSpec "not implemented" value, decoded as 0. A meter that did not implement total power (40098) went out as 0 W, a site in balance; any other field went out as 0.
  • It built the 32-bit word and compared it with 0x80000000, which is negative where Lua integers are 32 bits (docs/WRITING-A-DRIVER.md, "Numbers"). On this repository's lua55 every float decoded to -0.0. FTW uses wider numbers and was not affected.

Change

  • A miss counts only in a poll where another read answered, so a silent meter uses up no tries and is read again on the first poll it answers. A register that misses three times on a meter that does answer is asked again every five minutes instead of never.
  • A reply counts only when every word asked for came back.
  • NaN and infinity decode as nil, so the field is left out and the meter goes out only when total power answered with a number. Metrics skip what is left out.
  • The decoder works on the 16-bit halves, as ferroamp_modbus does.
  • driver_cleanup resets the new poll state. The Smart Meter has no serial block, so there is still no set_sn.

Test evidence

  • test_fronius_smart_meter_wakes.py, eighteen tests. Seventeen fail on 2.1.3 and all pass on 2.1.4. With only the decoder fixed on 2.1.3, sixteen still fail:
    • test_wakes_after_silence.lua (shared with the other PRs in this series): silent from start-up, silent mid-session, each register refused six times;
    • ten silent polls, then every field on the first poll that answers;
    • the meter left out when total power holds NaN; NaN fields left out of the meter and the metrics;
    • each of the twelve other registers asked again within five minutes after three refusals.
    • The meter left out when total power does not answer passes on 2.1.3 too; fields left out when their registers do not answer passes once the decoder is fixed.
  • make test-driver ID=fronius_smart_meter: 62 passed, 10 skipped.
  • make absent-register-report ID=fronius_smart_meter: every address settles except total power 40098, which emits nothing.
  • make invented-number-report ID=fronius_smart_meter: none. The driver was not in the baseline.
  • make check: 5592 passed, 927 skipped.

Not yet verified

  • No hardware run. The case needs a Smart Meter that is off or held by another Modbus client when FTW starts, and one that answers NaN for a field it does not implement.
  • The NaN and decoder fixes go beyond the wake-up. They are in this PR because they sit in the function the tests need, and the template meters in this series made the same NaN change; say if you want them split out.
  • drivers/lua/fronius.lua (the inverter) is not touched; it has its own PR, fix(fronius): read the inverter again after a silent start (2.3.2) #308.
  • CHANGELOG.md and drivers/tests/lua_harness/test_wakes_after_silence.lua are shared with the other PRs in this series; whichever merges later needs a rebase there.
  • After merge, FTW's pin in drivers/BUNDLED_SOURCE.json has to move.

🤖 Generated with Claude Code

…tart (2.1.4)

Every read went through a guard that left a register alone until restart
after three misses. A Smart Meter that was off, restarting or held by
another Modbus client at start-up used up every try while answering
nothing, and the driver then sent nothing until FTW restarted it. A float
that held NaN or infinity, the SunSpec "not implemented" value, went out
as 0. The decoder also built the 32-bit word and compared it with
0x80000000, which decodes every float wrong where Lua integers are 32
bits, as in this repository's test interpreter; FTW was not affected.

A miss now counts only in a poll where another read answered, and a
register that misses three times on a meter that does answer is asked
again every five minutes. A reply counts only when every word asked for
came back. NaN and infinity are left out, so the meter goes out only when
total power answered with a number. The decoder works on the 16-bit
halves.

test_fronius_smart_meter_wakes.py fails on 2.1.3 (17 of 18 cases; 16 of
18 with only the decoder fixed) and passes on 2.1.4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 5, 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-05T06:34:10.142078Z c5c3a3f 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.

This branch has not been deployed

No deployments
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