diff --git a/CHANGELOG.md b/CHANGELOG.md index 47930b6..171d6f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,14 @@ 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. 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 off-grid and restores the previous value after the grid has been up for diff --git a/main.py b/main.py index 920bd7d..6038664 100644 --- a/main.py +++ b/main.py @@ -53,6 +53,15 @@ # noise (see docs/superpowers/notes/2026-09-08-backup-threshold-investigation.md - # a flat constant for now, pending the adaptive-threshold formula explored # there). +# 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 MQTT_PORT = int(os.environ.get('MQTT_PORT', 1883)) @@ -270,7 +279,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=INVERTER_TIMEOUT_S, + 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..cbd8fec 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@v0.4.10-piomar.1 holidays==0.83 idna==3.19 itsdangerous==2.2.0