Reverted a lot of cruft
This commit is contained in:
19
gauge.py
19
gauge.py
@@ -883,8 +883,6 @@ def _subscribe_all(c):
|
||||
|
||||
def connect_mqtt():
|
||||
global client_ref, _mqtt_connected
|
||||
from umqtt.robust import MQTTClient
|
||||
gc.collect()
|
||||
info(f"Connecting to MQTT broker {MQTT_BROKER}:{MQTT_PORT} ...")
|
||||
last_error = None
|
||||
for attempt in range(3):
|
||||
@@ -892,8 +890,6 @@ def connect_mqtt():
|
||||
try:
|
||||
if client_ref is not None:
|
||||
try:
|
||||
if client_ref.sock:
|
||||
client_ref.sock.settimeout(2)
|
||||
client_ref.disconnect()
|
||||
except Exception:
|
||||
pass
|
||||
@@ -910,18 +906,11 @@ def connect_mqtt():
|
||||
client.connect()
|
||||
client_ref = client
|
||||
_mqtt_connected = True
|
||||
gc.collect()
|
||||
info(f"MQTT connected client_id={MQTT_CLIENT_ID} heap {gc.mem_free()} bytes")
|
||||
info(f"MQTT connected client_id={MQTT_CLIENT_ID}")
|
||||
return
|
||||
except Exception as e:
|
||||
last_error = e
|
||||
log_err(f"MQTT connect attempt {attempt + 1} failed: {type(e).__name__}: {e}")
|
||||
try:
|
||||
if client.sock:
|
||||
client.sock.settimeout(2)
|
||||
client.sock.close()
|
||||
except Exception:
|
||||
pass
|
||||
gc.collect()
|
||||
utime.sleep_ms(1000)
|
||||
|
||||
@@ -971,12 +960,6 @@ def check_mqtt():
|
||||
return True
|
||||
except Exception as e2:
|
||||
log_err(f"MQTT reconnect attempt {attempt + 1} failed: {e2}")
|
||||
try:
|
||||
if client_ref.sock:
|
||||
client_ref.sock.settimeout(2)
|
||||
client_ref.sock.close()
|
||||
except Exception:
|
||||
pass
|
||||
gc.collect()
|
||||
utime.sleep_ms(2000)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user