Skip to content

Forked goodwe with UDP late-response fixes, 5 inverter retries - #49

Merged
piomar123 merged 3 commits into
mainfrom
goodwe-fork-retries
Oct 23, 2026
Merged

piomar123 merged 3 commits into
mainfrom
goodwe-fork-retries

Conversation

@piomar123

Copy link
Copy Markdown
Owner

Why

I captured 5 minutes of the live inverter link on the Pi (632 requests, tcpdump on the dongle interface):

Reply time Grows with reply size: 48 B ≈ 90 ms, the 250 B runtime block ≈ 300 ms. p99 308 ms
Later than the 1 s timeout 2 replies. One was lost: the library had already closed the socket, so the Pi answered with ICMP port unreachable
Never answered 22 requests (3.5%), in bursts of a few seconds. 14 of them were the big runtime read
Retries Always exactly 1.0 s apart, 60 per request, so a dead link stalled the 1 Hz loop, and control writes behind it, for ~1 min per request

What

  • requirements.txt: goodwe is pinned to piomar123/goodwe@92a0eeb (branch udp-late-replies). That's 0.4.10 plus:
    • Upstream PR #156: one request lock per request, and retries counted per request. This matters here because the /config and /eco pages read settings while the poll loop and control writes share the same inverter object.
    • Late replies: retries of a request use the same socket, so a late reply to an earlier attempt still answers it. After a retried request the socket is closed, so a duplicate reply can't answer the next request. A Modbus RTU read reply doesn't say which registers it holds, so this matters.
    • Growing timeouts: each retry waits longer: 1, 1.5, 2.25, then 3 s.
    • Stray datagrams: a datagram that doesn't match the request is ignored instead of triggering an immediate retry.
  • main.py: INVERTER_RETRIES = 5 instead of 60. With the growing timeouts a request gives up after ~14 s, which still covers the observed loss bursts. With 60 retries a dead link would now stall for ~3 min.

The ad-hoc scripts _eco_mode.py and _goodwe_reader.py keep retries=60. They're only run by hand.

Upgrading

Run pip install -r requirements.txt after pulling (noted in CHANGELOG.md).

Test plan

  • goodwe fork: 140 tests pass, 8 of them new (tests/test_protocol_udp_retries.py). They cover:
    • a late reply accepted by the retry;
    • a late duplicate never answering the next request (with and without retries);
    • timeouts growing up to the cap;
    • stray datagrams ignored, while the timeout still fires;
    • socket reuse and close rules.
  • goodwe_manager: python -m unittest discover -s tests passes with the fork installed.
  • On the Pi after deploying: repeat the 5 min capture and compare unanswered requests, late replies, ICMP port-unreachable, and retry spacing.

🤖 Generated with Claude Code

piomar123 and others added 3 commits October 4, 2026 16:16
A 5 min capture of the inverter link (632 requests) showed replies in
90-300 ms, a few after the 1 s timeout - always lost, because the
library closed the socket on every retry - and 3.5% never answered, in
bursts of a few seconds. Retries came every 1.0 s, 60 times, so a dead
link stalled the 1 Hz loop for a minute per request.

Pin goodwe to the piomar123/goodwe fork (0.4.10 + upstream PR #156 +
late-response, growing retry timeout and stray-datagram fixes), and cut
retries to 5: with the growing timeouts that gives up after ~14 s, still
longer than the observed loss bursts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cepted

Replies take 90-300 ms, so a lost packet now costs a 0.6 s pause in the
1 Hz loop instead of 1 s. Safe with the forked goodwe: a reply slower
than the timeout still answers the retry. 5 retries now give up after
~8 s (0.6, 0.9, 1.35, then 1.8 s), still longer than the loss bursts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
v0.4.10-piomar.1 points at the same commit (92a0eeb); a tag survives a
rebase or deletion of the udp-late-replies branch.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@piomar123
piomar123 merged commit a2d5de3 into main Oct 23, 2026
1 check passed
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