From afe70da24d797da05009471a1452a2b4d8fcf314 Mon Sep 17 00:00:00 2001 From: "Adrian A. Baumann" Date: Tue, 21 Apr 2026 19:57:22 +0200 Subject: [PATCH] MQTT trouble,still --- gauge.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/gauge.py b/gauge.py index 4e13475..dc3aed3 100644 --- a/gauge.py +++ b/gauge.py @@ -28,6 +28,12 @@ import gc from umqtt.robust import MQTTClient from machine import UART +# Activate WiFi driver before any heavy heap allocation so it can claim its +# contiguous DRAM block before the Python heap fragments the address space. +gc.collect() +network.WLAN(network.STA_IF).active(True) +gc.collect() + # --------------------------------------------------------------------------- # Logging # --------------------------------------------------------------------------- @@ -530,7 +536,9 @@ _WIFI_CONNECT_ATTEMPTS = 3 def _reset_wifi_interface(): global _wifi_sta _wifi_sta = network.WLAN(network.STA_IF) - _wifi_sta.active(True) + if not _wifi_sta.active(): + _wifi_sta.active(True) + utime.sleep_ms(500) try: _wifi_sta.disconnect() except Exception: @@ -1301,10 +1309,13 @@ def apply_motion_defaults(): def main(): + gc.collect() info("=" * 48) info("Gauge MQTT controller starting") + info(f"Heap free: {gc.mem_free()} bytes") info("=" * 48) + gc.collect() connect_wifi(WIFI_SSID, WIFI_PASSWORD, force_reconnect=False) mqtt_attempts = 0