How to Build a Reliable Modbus Proxy With Timeouts, Retries, and Stale-Cache Alerts
A developer shares lessons learned after building a Modbus cache proxy for a SUN2000 solar inverter that silently served outdated data when the inverter shut down at night. The core problem was that naive asyncio reads without timeouts would hang indefinitely, leaving Home Assistant displaying stale values with no indication anything was wrong. The fix rests on three pillars: hard timeouts with inter-read spacing to accommodate the slow SDongle hardware, an asymmetric retry loop that recovers quickly from brief failures without flooding the device, and explicit staleness detection that logs a warning when cached data exceeds 120 seconds old. The implementation also distinguishes between survivable single-batch timeouts and fatal connection errors, using a break to exit the poll loop only when the connection is likely dead. The author frames this as a reliability playbook, arguing that a proxy that keeps running while serving wrong data is more dangerous than one that simply crashes.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in