fix
This commit is contained in:
+35
-36
@@ -92,7 +92,7 @@ bool loadBambuCredentials() {
|
|||||||
bambu_serialnr = g_bambu_serialnr.c_str();
|
bambu_serialnr = g_bambu_serialnr.c_str();
|
||||||
|
|
||||||
report_topic = "device/" + String(bambu_serialnr) + "/report";
|
report_topic = "device/" + String(bambu_serialnr) + "/report";
|
||||||
//request_topic = "device/" + String(bambu_serialnr) + "/request";
|
request_topic = "device/" + String(bambu_serialnr) + "/request";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Serial.println("Keine gültigen Bambu-Credentials gefunden.");
|
Serial.println("Keine gültigen Bambu-Credentials gefunden.");
|
||||||
@@ -214,7 +214,7 @@ bool sendMqttMessage(const String& payload) {
|
|||||||
// Check payload
|
// Check payload
|
||||||
if (payload.isEmpty()) {
|
if (payload.isEmpty()) {
|
||||||
Serial.println("Error: Empty payload!");
|
Serial.println("Error: Empty payload!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println("Attempting to send MQTT message:");
|
Serial.println("Attempting to send MQTT message:");
|
||||||
@@ -337,7 +337,6 @@ bool setBambuSpool(String payload) {
|
|||||||
doc["print"]["cali_idx"] = cali_idx.toInt();
|
doc["print"]["cali_idx"] = cali_idx.toInt();
|
||||||
doc["print"]["tray_id"] = trayId < 200 ? trayId : 254;
|
doc["print"]["tray_id"] = trayId < 200 ? trayId : 254;
|
||||||
|
|
||||||
// Serialize the JSON
|
|
||||||
String output;
|
String output;
|
||||||
serializeJson(doc, output);
|
serializeJson(doc, output);
|
||||||
Serial.println("Sending calibration to printer:");
|
Serial.println("Sending calibration to printer:");
|
||||||
@@ -617,19 +616,19 @@ void reconnect() {
|
|||||||
|
|
||||||
// Attempt to connect with clean session and will message
|
// Attempt to connect with clean session and will message
|
||||||
if (client.connect(clientId.c_str(), bambu_username, bambu_accesscode, nullptr, 0, true, nullptr)) {
|
if (client.connect(clientId.c_str(), bambu_username, bambu_accesscode, nullptr, 0, true, nullptr)) {
|
||||||
Serial.println("MQTT re/connected");
|
Serial.println("MQTT re/connected");
|
||||||
|
|
||||||
// Subscribe with QoS 1
|
// Subscribe with QoS 1
|
||||||
if (client.subscribe(report_topic.c_str(), 1)) {
|
if (client.subscribe(report_topic.c_str(), 1)) {
|
||||||
Serial.println("Successfully subscribed to topic with QoS 1: " + report_topic);
|
Serial.println("Successfully subscribed to topic with QoS 1: " + report_topic);
|
||||||
} else {
|
} else {
|
||||||
Serial.println("Failed to subscribe to topic: " + report_topic);
|
Serial.println("Failed to subscribe to topic: " + report_topic);
|
||||||
}
|
}
|
||||||
bambu_connected = true;
|
bambu_connected = true;
|
||||||
oledShowTopRow();
|
oledShowTopRow();
|
||||||
} else {
|
} else {
|
||||||
int state = client.state();
|
int state = client.state();
|
||||||
Serial.print("failed, rc=");
|
Serial.print("failed, rc=");
|
||||||
Serial.print(state);
|
Serial.print(state);
|
||||||
Serial.print(" (");
|
Serial.print(" (");
|
||||||
// Print detailed error message
|
// Print detailed error message
|
||||||
@@ -646,18 +645,18 @@ void reconnect() {
|
|||||||
default: Serial.print("UNKNOWN"); break;
|
default: Serial.print("UNKNOWN"); break;
|
||||||
}
|
}
|
||||||
Serial.println(") try again in 5 seconds");
|
Serial.println(") try again in 5 seconds");
|
||||||
bambu_connected = false;
|
bambu_connected = false;
|
||||||
oledShowTopRow();
|
oledShowTopRow();
|
||||||
|
|
||||||
yield();
|
yield();
|
||||||
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||||
if (retries > 5) {
|
if (retries > 5) {
|
||||||
Serial.println("Disable Bambu MQTT Task after 5 retries");
|
Serial.println("Disable Bambu MQTT Task after 5 retries");
|
||||||
vTaskDelete(BambuMqttTask);
|
vTaskDelete(BambuMqttTask);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
retries++;
|
|
||||||
}
|
}
|
||||||
|
retries++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -672,7 +671,7 @@ void mqtt_loop(void * parameter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned long now = millis();
|
unsigned long now = millis();
|
||||||
|
|
||||||
if (!client.connected()) {
|
if (!client.connected()) {
|
||||||
Serial.println("Connection lost, attempting reconnect...");
|
Serial.println("Connection lost, attempting reconnect...");
|
||||||
reconnect();
|
reconnect();
|
||||||
@@ -726,8 +725,8 @@ bool setupMqtt() {
|
|||||||
// Verbinden mit dem MQTT-Server
|
// Verbinden mit dem MQTT-Server
|
||||||
bool connected = true;
|
bool connected = true;
|
||||||
if (client.connect(clientId.c_str(), bambu_username, bambu_accesscode, nullptr, 0, true, nullptr))
|
if (client.connect(clientId.c_str(), bambu_username, bambu_accesscode, nullptr, 0, true, nullptr))
|
||||||
{
|
{
|
||||||
client.setCallback(mqtt_callback);
|
client.setCallback(mqtt_callback);
|
||||||
client.setBufferSize(16384); // Increased to 16KB to handle larger JSON
|
client.setBufferSize(16384); // Increased to 16KB to handle larger JSON
|
||||||
|
|
||||||
// Subscribe with QoS 1
|
// Subscribe with QoS 1
|
||||||
@@ -737,13 +736,13 @@ bool setupMqtt() {
|
|||||||
Serial.println("Failed to subscribe to topic: " + report_topic);
|
Serial.println("Failed to subscribe to topic: " + report_topic);
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println("MQTT-Client initialisiert");
|
Serial.println("MQTT-Client initialisiert");
|
||||||
|
|
||||||
oledShowMessage("Bambu Connected");
|
oledShowMessage("Bambu Connected");
|
||||||
bambu_connected = true;
|
bambu_connected = true;
|
||||||
oledShowTopRow();
|
oledShowTopRow();
|
||||||
|
|
||||||
xTaskCreatePinnedToCore(
|
xTaskCreatePinnedToCore(
|
||||||
mqtt_loop, /* Function to implement the task */
|
mqtt_loop, /* Function to implement the task */
|
||||||
"BambuMqtt", /* Name of the task */
|
"BambuMqtt", /* Name of the task */
|
||||||
16384, /* Stack size in words */
|
16384, /* Stack size in words */
|
||||||
@@ -751,18 +750,18 @@ bool setupMqtt() {
|
|||||||
mqttTaskPrio, /* Priority of the task */
|
mqttTaskPrio, /* Priority of the task */
|
||||||
&BambuMqttTask, /* Task handle. */
|
&BambuMqttTask, /* Task handle. */
|
||||||
mqttTaskCore); /* Core where the task should run */
|
mqttTaskCore); /* Core where the task should run */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.println("Fehler: Konnte sich nicht beim MQTT-Server anmelden");
|
Serial.println("Fehler: Konnte sich nicht beim MQTT-Server anmelden");
|
||||||
oledShowMessage("Bambu Connection Failed");
|
oledShowMessage("Bambu Connection Failed");
|
||||||
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||||
connected = false;
|
connected = false;
|
||||||
oledShowTopRow();
|
oledShowTopRow();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!connected) return false;
|
if (!connected) return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.println("Fehler: Keine MQTT-Daten vorhanden");
|
Serial.println("Fehler: Keine MQTT-Daten vorhanden");
|
||||||
|
|||||||
Reference in New Issue
Block a user