mqtt_logger: cached values carry no staleness information and connection gaps are invisible #3
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Cached topics (forecasts, Zappi state, weather auxiliaries) persist their last received value indefinitely. If a publisher dies or stops sending, records keep being emitted that look complete but carry arbitrarily old values, and nothing in the stream reveals this.
Separately, nothing is recorded about connection lifecycle: the 2026-07-03 to 2026-07-13 hole in the stats file has no forensics trail - it is impossible to tell whether the logger died, the broker restarted, or the machine was off.
A related hazard: the client subscribes once at startup and uses a clean session, so after a broker restart it may reconnect successfully while subscribed to nothing - silently receiving no data until manually restarted.
Findings
cached: Truetopic values persist inlatestforever; there is no record of when each field was last published, so a dead publisher is indistinguishable from a fresh one.clean_sessiondefaults to True (client.py) and there is no automatic resubscribe anywhere inclient.py. Subscribing once inmain()means a broker restart can leave the client connected but receiving nothing — a plausible cause of the silent multi-day gap in July.on_connect(client, userdata, connect_flags, reason_code, properties)/on_disconnect(client, userdata, disconnect_flags, reason_code, properties).Plan of attack
published_at(monotonic) per field, updated atomically together with the value cache; each record gains an_age_smap covering exactly its payload fields, so analysis can reject records whose cached sources went quiet.on_connect/on_disconnecthandlers emitting JSON event lines ("event": "connect"/"disconnect", withreason_code) into the same stream;on_connectresubscribes to all topics (fixes the silent-reconnect hole). Move subscription frommain()intoon_connectas the single source of truth.:sparkles: add per-field freshness ages and connect/disconnect markerson branchfix/issue-2-mqtt-logger-quality.