Discovery missing effects

This commit is contained in:
2026-04-21 23:34:17 +02:00
parent c57e0d8ae2
commit ffd807ff45

View File

@@ -889,12 +889,20 @@ def connect_mqtt():
for attempt in range(3): for attempt in range(3):
gc.collect() gc.collect()
try: try:
_wifi_sta = network.WLAN(network.STA_IF) import usocket
if _wifi_sta.isconnected(): s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
_wifi_sta.active(False) s.settimeout(3)
utime.sleep_ms(100) try:
_wifi_sta.active(True) s.connect((MQTT_BROKER, MQTT_PORT))
utime.sleep_ms(200) info(" broker port reachable")
except Exception as e:
warn(f" broker unreachable: {e}")
try:
s.close()
except Exception:
pass
del usocket
gc.collect()
if client_ref is not None: if client_ref is not None:
try: try:
if client_ref.sock: if client_ref.sock:
@@ -1350,7 +1358,7 @@ def main():
info("=" * 48) info("=" * 48)
gc.collect() gc.collect()
connect_wifi(WIFI_SSID, WIFI_PASSWORD, force_reconnect=True) connect_wifi(WIFI_SSID, WIFI_PASSWORD)
mqtt_attempts = 0 mqtt_attempts = 0
while True: while True:
@@ -1363,7 +1371,7 @@ def main():
if mqtt_attempts % 3 == 0: if mqtt_attempts % 3 == 0:
log_err("WiFi may be stale — forcing reconnect...") log_err("WiFi may be stale — forcing reconnect...")
try: try:
connect_wifi(WIFI_SSID, WIFI_PASSWORD, force_reconnect=True) connect_wifi(WIFI_SSID, WIFI_PASSWORD)
except Exception as we: except Exception as we:
log_err(f"WiFi reconnect failed: {we}") log_err(f"WiFi reconnect failed: {we}")
utime.sleep_ms(5000) utime.sleep_ms(5000)