Discovery missing effects
This commit is contained in:
18
gauge.py
18
gauge.py
@@ -884,15 +884,21 @@ def connect_mqtt():
|
||||
global client_ref, _mqtt_connected
|
||||
from umqtt.robust import MQTTClient
|
||||
gc.collect()
|
||||
info(f"Heap before MQTT: {gc.mem_free()} bytes")
|
||||
info(f"Connecting to MQTT broker {MQTT_BROKER}:{MQTT_PORT} ...")
|
||||
last_error = None
|
||||
for attempt in range(3):
|
||||
gc.collect()
|
||||
info(f" attempt {attempt + 1}: heap {gc.mem_free()} bytes")
|
||||
try:
|
||||
_wifi_sta = network.WLAN(network.STA_IF)
|
||||
if _wifi_sta.isconnected():
|
||||
_wifi_sta.active(False)
|
||||
utime.sleep_ms(100)
|
||||
_wifi_sta.active(True)
|
||||
utime.sleep_ms(200)
|
||||
if client_ref is not None:
|
||||
try:
|
||||
if client_ref.sock:
|
||||
client_ref.sock.settimeout(2)
|
||||
client_ref.disconnect()
|
||||
except Exception:
|
||||
pass
|
||||
@@ -916,7 +922,9 @@ def connect_mqtt():
|
||||
last_error = e
|
||||
log_err(f"MQTT connect attempt {attempt + 1} failed: {type(e).__name__}: {e}")
|
||||
try:
|
||||
client.sock.close()
|
||||
if client.sock:
|
||||
client.sock.settimeout(2)
|
||||
client.sock.close()
|
||||
except Exception:
|
||||
pass
|
||||
gc.collect()
|
||||
@@ -969,7 +977,9 @@ def check_mqtt():
|
||||
except Exception as e2:
|
||||
log_err(f"MQTT reconnect attempt {attempt + 1} failed: {e2}")
|
||||
try:
|
||||
client_ref.sock.close()
|
||||
if client_ref.sock:
|
||||
client_ref.sock.settimeout(2)
|
||||
client_ref.sock.close()
|
||||
except Exception:
|
||||
pass
|
||||
gc.collect()
|
||||
|
||||
Reference in New Issue
Block a user