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
|
global client_ref, _mqtt_connected
|
||||||
from umqtt.robust import MQTTClient
|
from umqtt.robust import MQTTClient
|
||||||
gc.collect()
|
gc.collect()
|
||||||
info(f"Heap before MQTT: {gc.mem_free()} bytes")
|
|
||||||
info(f"Connecting to MQTT broker {MQTT_BROKER}:{MQTT_PORT} ...")
|
info(f"Connecting to MQTT broker {MQTT_BROKER}:{MQTT_PORT} ...")
|
||||||
last_error = None
|
last_error = None
|
||||||
for attempt in range(3):
|
for attempt in range(3):
|
||||||
gc.collect()
|
gc.collect()
|
||||||
info(f" attempt {attempt + 1}: heap {gc.mem_free()} bytes")
|
|
||||||
try:
|
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:
|
if client_ref is not None:
|
||||||
try:
|
try:
|
||||||
|
if client_ref.sock:
|
||||||
|
client_ref.sock.settimeout(2)
|
||||||
client_ref.disconnect()
|
client_ref.disconnect()
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
@@ -916,7 +922,9 @@ def connect_mqtt():
|
|||||||
last_error = e
|
last_error = e
|
||||||
log_err(f"MQTT connect attempt {attempt + 1} failed: {type(e).__name__}: {e}")
|
log_err(f"MQTT connect attempt {attempt + 1} failed: {type(e).__name__}: {e}")
|
||||||
try:
|
try:
|
||||||
client.sock.close()
|
if client.sock:
|
||||||
|
client.sock.settimeout(2)
|
||||||
|
client.sock.close()
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
gc.collect()
|
gc.collect()
|
||||||
@@ -969,7 +977,9 @@ def check_mqtt():
|
|||||||
except Exception as e2:
|
except Exception as e2:
|
||||||
log_err(f"MQTT reconnect attempt {attempt + 1} failed: {e2}")
|
log_err(f"MQTT reconnect attempt {attempt + 1} failed: {e2}")
|
||||||
try:
|
try:
|
||||||
client_ref.sock.close()
|
if client_ref.sock:
|
||||||
|
client_ref.sock.settimeout(2)
|
||||||
|
client_ref.sock.close()
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|||||||
Reference in New Issue
Block a user