feat: implement tray ID handling and add bambu_restart function for MQTT management

This commit is contained in:
Manuel Weiser 2025-02-15 09:05:22 +01:00
parent 3e1490cafc
commit d1f22c78f7
2 changed files with 36 additions and 6 deletions

View File

@ -193,7 +193,7 @@ bool setBambuSpool(String payload) {
int maxTemp = doc["nozzle_temp_max"];
String type = doc["type"].as<String>();
String brand = doc["brand"].as<String>();
String tray_info_idx = doc["tray_info_idx"].as<String>();
String tray_info_idx = (doc["tray_info_idx"].as<String>() != "-1") ? doc["tray_info_idx"].as<String>() : "";
if (tray_info_idx == "") tray_info_idx = (brand != "" && type != "") ? findFilamentIdx(brand, type) : "";
String setting_id = doc["cali_idx"].as<String>();
@ -223,6 +223,33 @@ bool setBambuSpool(String payload) {
return false;
}
doc.clear();
if (setting_id != "") {
doc["print"]["sequence_id"] = 0;
doc["print"]["command"] = "extrusion_cali_sel";
doc["print"]["ams_id"] = amsId < 200 ? amsId : 255;
doc["print"]["tray_id"] = trayId < 200 ? trayId : 254;
doc["print"]["filament_id"] = tray_info_idx;
doc["print"]["nozzle_diameter"] = "0.4";
doc["print"]["cali_idx"] = setting_id.toInt();
// Serialize the JSON
String output;
serializeJson(doc, output);
if (sendMqttMessage(output)) {
Serial.println("Setting ID successfully set");
}
else
{
Serial.println("Failed to set setting ID");
return false;
}
doc.clear();
}
return true;
}
@ -305,11 +332,6 @@ void mqtt_callback(char* topic, byte* payload, unsigned int length) {
if (!foundExternal) hasChanges = true;
}
// Wenn Bambu connection changed
if (bambu_connected != doc["print"]["bambu_connected"].as<bool>()) {
hasChanges = true;
}
if (!hasChanges) return;
// Fortfahren mit der bestehenden Verarbeitung, da Änderungen gefunden wurden
@ -512,4 +534,11 @@ bool setupMqtt() {
return false;
}
return true;
}
void bambu_restart() {
if (BambuMqttTask) {
vTaskDelete(BambuMqttTask);
}
setupMqtt();
}

View File

@ -33,5 +33,6 @@ bool saveBambuCredentials(const String& bambu_ip, const String& bambu_serialnr,
bool setupMqtt();
void mqtt_loop(void * parameter);
bool setBambuSpool(String payload);
void bambu_restart();
#endif