From dfdfd3f48c179d87aafe2b3ed0534ec38fed7f99 Mon Sep 17 00:00:00 2001 From: piomar123 Date: Sun, 4 Oct 2026 16:16:25 +0200 Subject: [PATCH 1/3] Use forked goodwe with UDP late-response fixes, 5 inverter retries 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 --- CHANGELOG.md | 7 +++++++ main.py | 8 +++++++- requirements.txt | 3 ++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47930b6..1445e76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,13 @@ grouped under `Unreleased` until that changes. ### Changed +- goodwe is now a pinned fork (0.4.10 + upstream PR #156 + UDP fixes): a + late inverter response to an earlier attempt is accepted instead of lost, + each retry waits longer (1, 1.5, 2.25, then 3 s), and stray datagrams no + longer trigger instant retries. Inverter retries per request went from + 60 to 5, so a dead link fails after ~14 s instead of stalling the poll + loop for a minute (3 min with the longer retry waits). Run + `pip install -r requirements.txt` after pulling. - Optional off-grid shadow scan guard (off by default): `OFF_GRID_SHADOW_SCAN_GUARD=on` turns shadow scan off while the inverter is off-grid and restores the previous value after the grid has been up for diff --git a/main.py b/main.py index 920bd7d..d0cb46a 100644 --- a/main.py +++ b/main.py @@ -53,6 +53,11 @@ # noise (see docs/superpowers/notes/2026-09-08-backup-threshold-investigation.md - # a flat constant for now, pending the adaptive-threshold formula explored # there). +# Per request: with the forked goodwe each retry waits longer (1, 1.5, 2.25, +# then 3 s), so 5 retries give up after ~14 s - longer than the loss bursts +# seen on the Wi-Fi link (a few s), short enough that a dead link doesn't +# stall the 1 Hz loop (and control writes) for minutes before reconnecting. +INVERTER_RETRIES = 5 BACKUP_ACTIVE_THRESHOLD_W = float(os.environ.get('BACKUP_ACTIVE_THRESHOLD_W', 35)) MQTT_HOST = os.environ.get('MQTT_HOST') or None MQTT_PORT = int(os.environ.get('MQTT_PORT', 1883)) @@ -270,7 +275,8 @@ async def _get_inverter_data_with_retry(self): async def _get_inverter_data(self): logger.info(f'Connecting to {self._inverter_address}') - self._inverter = await goodwe.connect(self._inverter_address, family='ET', timeout=1, retries=60) + self._inverter = await goodwe.connect(self._inverter_address, family='ET', timeout=1, + retries=INVERTER_RETRIES) logger.info(f'Connected to the inverter') if control_runtime_instance is not None: control_runtime_instance.attach(self._inverter) diff --git a/requirements.txt b/requirements.txt index 856a976..512bb13 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,7 +9,8 @@ contourpy==1.3.3 cycler==0.12.1 Flask==3.1.3 fonttools==4.64.0 -goodwe==0.4.10 +# Fork of 0.4.10 + upstream PR #156 + late-response/retry-timeout fixes (branch udp-late-replies) +goodwe @ git+https://github.com/piomar123/goodwe.git@92a0eeb662c4879f22a01f12f13f9db6a9ddc255 holidays==0.83 idna==3.19 itsdangerous==2.2.0 From 9987b29ee559435bad2617f84ec249a87385eee4 Mon Sep 17 00:00:00 2001 From: piomar123 Date: Sun, 4 Oct 2026 16:34:36 +0200 Subject: [PATCH 2/3] Inverter timeout 0.6 s: lost packets cost less, late replies still accepted 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 --- CHANGELOG.md | 7 ++++--- main.py | 14 +++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1445e76..171d6f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,9 +11,10 @@ grouped under `Unreleased` until that changes. - goodwe is now a pinned fork (0.4.10 + upstream PR #156 + UDP fixes): a late inverter response to an earlier attempt is accepted instead of lost, each retry waits longer (1, 1.5, 2.25, then 3 s), and stray datagrams no - longer trigger instant retries. Inverter retries per request went from - 60 to 5, so a dead link fails after ~14 s instead of stalling the poll - loop for a minute (3 min with the longer retry waits). Run + longer trigger instant retries. The inverter timeout went from 1 s to + 0.6 s (replies take at most ~0.3 s, and a slower one is still accepted) + and retries per request from 60 to 5, so a dead link fails after ~8 s + instead of stalling the poll loop for a minute. Run `pip install -r requirements.txt` after pulling. - Optional off-grid shadow scan guard (off by default): `OFF_GRID_SHADOW_SCAN_GUARD=on` turns shadow scan off while the inverter is diff --git a/main.py b/main.py index d0cb46a..6038664 100644 --- a/main.py +++ b/main.py @@ -53,10 +53,14 @@ # noise (see docs/superpowers/notes/2026-09-08-backup-threshold-investigation.md - # a flat constant for now, pending the adaptive-threshold formula explored # there). -# Per request: with the forked goodwe each retry waits longer (1, 1.5, 2.25, -# then 3 s), so 5 retries give up after ~14 s - longer than the loss bursts -# seen on the Wi-Fi link (a few s), short enough that a dead link doesn't -# stall the 1 Hz loop (and control writes) for minutes before reconnecting. +# Replies take 90-300 ms (by size), so a lost packet is noticed after +# 0.6 s instead of 1 s; a reply slower than that is still accepted, since +# the forked goodwe keeps the socket open across retries. Each retry waits +# longer (0.6, 0.9, 1.35, then 1.8 s), so 5 retries give up after ~8 s - +# longer than the loss bursts seen on the Wi-Fi link (a few s), short +# enough that a dead link doesn't stall the 1 Hz loop (and control writes) +# for minutes before reconnecting. +INVERTER_TIMEOUT_S = 0.6 INVERTER_RETRIES = 5 BACKUP_ACTIVE_THRESHOLD_W = float(os.environ.get('BACKUP_ACTIVE_THRESHOLD_W', 35)) MQTT_HOST = os.environ.get('MQTT_HOST') or None @@ -275,7 +279,7 @@ async def _get_inverter_data_with_retry(self): async def _get_inverter_data(self): logger.info(f'Connecting to {self._inverter_address}') - self._inverter = await goodwe.connect(self._inverter_address, family='ET', timeout=1, + self._inverter = await goodwe.connect(self._inverter_address, family='ET', timeout=INVERTER_TIMEOUT_S, retries=INVERTER_RETRIES) logger.info(f'Connected to the inverter') if control_runtime_instance is not None: From 65b31493144a38e17cec723bdf37fe5a8927b7bd Mon Sep 17 00:00:00 2001 From: piomar123 Date: Sun, 11 Oct 2026 20:07:57 +0200 Subject: [PATCH 3/3] Pin the goodwe fork by tag instead of a bare commit 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 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 512bb13..cbd8fec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,7 +10,7 @@ cycler==0.12.1 Flask==3.1.3 fonttools==4.64.0 # Fork of 0.4.10 + upstream PR #156 + late-response/retry-timeout fixes (branch udp-late-replies) -goodwe @ git+https://github.com/piomar123/goodwe.git@92a0eeb662c4879f22a01f12f13f9db6a9ddc255 +goodwe @ git+https://github.com/piomar123/goodwe.git@v0.4.10-piomar.1 holidays==0.83 idna==3.19 itsdangerous==2.2.0