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