diff --git a/gauge.py b/gauge.py index 9731ace..3e2fa4a 100644 --- a/gauge.py +++ b/gauge.py @@ -561,6 +561,7 @@ def connect_wifi(ssid, password, timeout_s=15, force_reconnect=False): last_error = None for attempt in range(_WIFI_CONNECT_ATTEMPTS): info(f"WiFi connecting to '{ssid}' (attempt {attempt + 1}/{_WIFI_CONNECT_ATTEMPTS}) ...") + _reset_wifi_interface() try: _wifi_sta.connect(ssid, password) deadline = utime.time() + timeout_s @@ -600,7 +601,7 @@ def check_wifi(): log_err("WiFi lost connection — attempting reconnect...") try: - ip = connect_wifi(WIFI_SSID, WIFI_PASSWORD, timeout_s=15, force_reconnect=True) + ip = connect_wifi(WIFI_SSID, WIFI_PASSWORD, timeout_s=15) info(f"WiFi reconnected! IP:{ip}") except Exception as e: log_err(f"WiFi reconnect failed: {e}") @@ -889,20 +890,6 @@ def connect_mqtt(): for attempt in range(3): gc.collect() try: - import usocket - s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM) - s.settimeout(3) - try: - s.connect((MQTT_BROKER, MQTT_PORT)) - 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: try: if client_ref.sock: