From b3e2ef0f81a3d7b71853cdb6f16030d1cbbc07dd Mon Sep 17 00:00:00 2001 From: "Adrian A. Baumann" Date: Tue, 21 Apr 2026 18:41:10 +0200 Subject: [PATCH] MQTT trouble --- gauge.py | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/gauge.py b/gauge.py index f73546e..8179f5d 100644 --- a/gauge.py +++ b/gauge.py @@ -877,28 +877,6 @@ def _subscribe_all(c): c.subscribe(f"{prefix}/status_led/green/set") -def _mqtt_connect_with_timeout(client, timeout_s=10): - """Call client.connect() with a socket-level timeout to avoid blocking forever.""" - try: - import usocket as _sm - except ImportError: - import socket as _sm - _orig = _sm.socket - def _timed(*a, **kw): - s = _orig(*a, **kw) - s.settimeout(timeout_s) - return s - _sm.socket = _timed - try: - client.connect() - finally: - _sm.socket = _orig - try: - client.sock.settimeout(None) - except Exception: - pass - - def connect_mqtt(): global client_ref, _mqtt_connected info(f"Connecting to MQTT broker {MQTT_BROKER}:{MQTT_PORT} ...") @@ -920,7 +898,7 @@ def connect_mqtt(): keepalive=30, ) client.set_callback(on_message) - _mqtt_connect_with_timeout(client) + client.connect() client_ref = client _mqtt_connected = True info(f"MQTT connected client_id={MQTT_CLIENT_ID}")