From 49f36bb25be9b5716d307adbc9357d6d96bfb809 Mon Sep 17 00:00:00 2001 From: Manuel Weiser Date: Fri, 14 Feb 2025 16:46:16 +0100 Subject: [PATCH] fix: update MQTT connection logic to ensure proper task creation and connection handling --- src/bambu.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/bambu.cpp b/src/bambu.cpp index ad73bb7..3cf345e 100644 --- a/src/bambu.cpp +++ b/src/bambu.cpp @@ -463,7 +463,7 @@ bool setupMqtt() { client.setServer(bambu_ip, 8883); // Verbinden mit dem MQTT-Server - bool connected = false; + bool connected = true; if (client.connect(bambu_serialnr, bambu_username, bambu_accesscode)) { client.setCallback(mqtt_callback); @@ -476,15 +476,26 @@ bool setupMqtt() { oledShowMessage("Bambu Connected"); bambu_connected = true; oledShowTopRow(); + + xTaskCreatePinnedToCore( + mqtt_loop, /* Function to implement the task */ + "BambuMqtt", /* Name of the task */ + 10000, /* Stack size in words */ + NULL, /* Task input parameter */ + mqttTaskPrio, /* Priority of the task */ + &BambuMqttTask, /* Task handle. */ + mqttTaskCore); /* Core where the task should run */ } else { Serial.println("Fehler: Konnte sich nicht beim MQTT-Server anmelden"); oledShowMessage("Bambu Connection Failed"); - oledShowTopRow(); vTaskDelay(2000 / portTICK_PERIOD_MS); - return false; + connected = false; + oledShowTopRow(); } + + if (!connected) return false; } else {