Skip to content

fix(ctek, ctek_v2, ctek_hybrid): read the charger again after a silent start - #303

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

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

Conversation

@frahlg

@frahlg frahlg commented Dec 4, 2026

Copy link
Copy Markdown
Member

Problem

ctek, ctek_v2 and ctek_hybrid sent every poll read through one guard (probe_read, GIVE_UP_AFTER = 3) that left a register alone until restart after three misses. That included the telemetry block (0x1100 / 0x2100), the control block and the serial. A charger that was off when FTW started, or held by another Modbus client, used up all of them while answering nothing. From then on the driver:

  • sent w = 0, l1_a = 0 … l3_v = 0 and lifetime_wh = 0 on every poll, which Core takes as a live charger drawing nothing;
  • never read the serial number Core keys the device on.

Only a restart brought it back. Core reloads a driver with nothing left to read only if an earlier read had succeeded, so this did not heal on its own.

Change

  • The telemetry block is asked on every poll and never given up. While it is silent the driver sends nothing, not zeros, and logs once when it stops and once when it answers again.
  • The control block and the serial are asked only in a poll where the charger answered: after the telemetry block for ctek and ctek_v2; after MQTT em or the Modbus telemetry for ctek_hybrid. The serial is read last, so a timeout there cannot make the host skip the poll's other reads.
  • A register that misses three times on a charger that does answer is asked again every five minutes, not never. A short reply counts as a miss.
  • Register addresses, scales, the MQTT path and the control path are unchanged.
  • All three drivers leave invented-number-baseline.json (9 fields each before).

Test evidence

  • test_wakes_after_silence.lua (shared with fix(saj): read the serial and battery again after the inverter wakes (1.3.1) #301), run by test_ctek_wakes.py, test_ctek_v2_wakes.py, test_ctek_hybrid_wakes.py: silent from driver_init for eight polls then answering; silent for eight polls mid-session; each register refused six times while the rest answer, which must be asked again within five minutes. The old drivers fail: asleep at start-up: register 4099 not read after the device answered (8195 for ctek_v2).
  • make test-driver: ctek 126 passed, ctek_v2 42 passed, ctek_hybrid 42 passed.
  • make absent-register-report: every address settles except the telemetry block, which emits nothing while it fails (allowed).
  • make invented-number-report: 0 invented fields for all three.
  • make check: 5577 passed, 927 skipped.

Not yet verified

  • No hardware run. A charger that is unreachable now shows as offline in FTW instead of as a charger reading 0 W; nobody has checked how the apps show that.
  • ctek_hybrid with MQTT em fresh and Modbus dead still gives up the control block after three misses and asks every five minutes, as before plus the retry.
  • After merge, FTW's pin in drivers/BUNDLED_SOURCE.json has to move.

🤖 Generated with Claude Code

…t start (0.3.5, 0.3.5, 0.3.4)

All three drivers sent every poll read, the telemetry block included,
through one guard that gave a register three tries and then left it
alone until restart. A charger that was off at start-up, or held by
another Modbus client, used up every try while answering nothing. The
driver then sent 0 W, 0 A and 0 V for the rest of the process and never
read the serial number FTW Core keys the device on.

The telemetry block is now asked on every poll and never given up; while
it is silent the driver sends nothing rather than zeros. The control
block and the serial are asked only in a poll where the charger
answered (for ctek_hybrid, over MQTT em or Modbus), the serial last. A
register that misses three times on a charger that does answer is asked
again every five minutes instead of never. All three leave
invented-number-baseline.json.

test_wakes_after_silence.lua runs each driver silent from start-up,
silent mid-session, and with each register refused six times. The old
drivers fail it; the new ones pass.

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 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-04T18:25:34.502037Z bbad937 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bbad9372d9

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

host.emit_metric("ev_mqtt_em_age_ms", em_age_ms < 0 and 0 or em_age_ms)
host.emit_metric("ev_mqtt_em_fresh", em_fresh and 1 or 0)

if modbus_answered then read_serial() end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Allow serial discovery when MQTT telemetry is fresh

When MQTT em telemetry stays fresh but the control-block read is refused, modbus_answered never becomes true, so the serial register is never attempted—even if it answers normally. In the Lua harness, refusing only 0x1200 while delivering fresh MQTT telemetry produces 130 EV frames with no serial read; the parent revision discovers the serial immediately. This prevents Core from obtaining the hardware identity and also blocks serial-dependent MQTT subscriptions. Permit the serial probe after fresh MQTT telemetry as well, retaining its bounded retry behavior. This also violates AGENTS.md's requirement to report stable hardware identity early.

AGENTS.md reference: AGENTS.md:L84-L84

Useful? React with 👍 / 👎.

@miravoss26 miravoss26 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctek, ctek_v2, ctek_hybrid: the telemetry block is never given up, a silent charger now sends nothing instead of zeros, and other refused registers are retried every five minutes.

  • Medium, drivers/lua/ctek_hybrid.lua (driver_poll): I agree with the open Codex finding. With MQTT em fresh, modbus_answered is only set by a successful control-block read, so if 0x1200 (REG_CHARGE_LIMIT) is refused, read_serial() is never called, even if the serial would answer. The old driver asked for the serial first. It also blocks the subscriptions that need the serial. Letting a fresh-em poll try the serial too (still bounded by probe_read) would fix it.
  • ctek and ctek_v2: no findings.
  • Security: no secrets, new dependencies, new network destinations or write-path changes in the driver diff.

Needs a fix or a human decision on the hybrid serial case before merge. I read the driver diff; I did not run the tests myself.

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.

2 participants