Compare commits

...

4 Commits

4 changed files with 73 additions and 51 deletions
+2
View File
@@ -129,6 +129,7 @@
if (data.status === 'success' || lastReceivedProgress >= 98) {
clearTimeout(wsReconnectTimer);
setTimeout(() => {
window.location.reload(true);
window.location.href = '/';
}, 30000);
}
@@ -164,6 +165,7 @@
status.className = 'status success';
status.style.display = 'block';
setTimeout(() => {
window.location.reload(true);
window.location.href = '/';
}, 30000);
}
+56 -50
View File
@@ -553,30 +553,34 @@ void reconnect() {
oledShowTopRow();
// Attempt to connect
if (client.connect(bambu_serialnr, bambu_username, bambu_accesscode)) {
Serial.println("MQTT re/connected");
String clientId = String(bambu_serialnr) + "_" + String(random(0, 100));
if (client.connect(clientId.c_str(), bambu_username, bambu_accesscode)){
Serial.println("MQTT re/connected");
client.subscribe(report_topic.c_str());
bambu_connected = true;
oledShowTopRow();
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
bambu_connected = false;
oledShowTopRow();
yield();
vTaskDelay(5000 / portTICK_PERIOD_MS);
if (retries > 5) {
Serial.println("Disable Bambu MQTT Task after 5 retries");
//vTaskSuspend(BambuMqttTask);
vTaskDelete(BambuMqttTask);
break;
client.subscribe(report_topic.c_str());
bambu_connected = true;
oledShowTopRow();
}
else
{
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
bambu_connected = false;
oledShowTopRow();
retries++;
}
yield();
vTaskDelay(5000 / portTICK_PERIOD_MS);
if (retries > 5)
{
Serial.println("Disable Bambu MQTT Task after 5 retries");
// vTaskSuspend(BambuMqttTask);
vTaskDelete(BambuMqttTask);
break;
}
retries++;
}
}
}
@@ -619,38 +623,40 @@ bool setupMqtt() {
// Verbinden mit dem MQTT-Server
bool connected = true;
if (client.connect(bambu_serialnr, bambu_username, bambu_accesscode))
{
client.setCallback(mqtt_callback);
client.setBufferSize(5120);
client.subscribe(report_topic.c_str());
//client.subscribe(request_topic.c_str());
Serial.println("MQTT-Client initialisiert");
String clientId = String(bambu_serialnr) + "_" + String(random(0, 100));
if (client.connect(clientId.c_str(), bambu_username, bambu_accesscode))
{
client.setCallback(mqtt_callback);
client.setBufferSize(5120);
client.subscribe(report_topic.c_str());
// client.subscribe(request_topic.c_str());
Serial.println("MQTT-Client initialisiert");
oledShowMessage("Bambu Connected");
bambu_connected = true;
oledShowTopRow();
oledShowMessage("Bambu Connected");
bambu_connected = true;
oledShowTopRow();
xTaskCreatePinnedToCore(
mqtt_loop, /* Function to implement the task */
"BambuMqtt", /* Name of the task */
10240, /* 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");
vTaskDelay(2000 / portTICK_PERIOD_MS);
connected = false;
oledShowTopRow();
xTaskCreatePinnedToCore(
mqtt_loop, /* Function to implement the task */
"BambuMqtt", /* Name of the task */
10240, /* 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");
vTaskDelay(2000 / portTICK_PERIOD_MS);
connected = false;
oledShowTopRow();
}
if (!connected)
return false;
}
if (!connected) return false;
}
else
{
Serial.println("Fehler: Keine MQTT-Daten vorhanden");
+4
View File
@@ -98,6 +98,10 @@ void loop() {
// Wenn Bambu auto set Spool aktiv
if (autoSendToBambu && autoSetToBambuSpoolId > 0) {
if (!bambu_connected)
{
bambu_restart();
}
if (intervalElapsed(currentMillis, lastAutoSetBambuAmsTime, autoSetBambuAmsInterval))
{
if (hasReadRfidTag == 0)
+11 -1
View File
@@ -286,6 +286,16 @@ void setupWebserver(AsyncWebServer &server) {
}
String url = request->getParam("url")->value();
if (url.indexOf("http://") == -1 && url.indexOf("https://") == -1)
{
url = "http://" + url;
}
// Remove trailing slash if exists
if (url.length() > 0 && url.charAt(url.length() - 1) == '/')
{
url = url.substring(0, url.length() - 1);
}
bool octoEnabled = (request->getParam("octoEnabled")->value() == "true") ? true : false;
String octoUrl = request->getParam("octoUrl")->value();
String octoToken = (request->getParam("octoToken")->value() != "") ? request->getParam("octoToken")->value() : "";
@@ -300,7 +310,7 @@ void setupWebserver(AsyncWebServer &server) {
request->send(200, "application/json", jsonResponse);
});
// Route für das Überprüfen der Spoolman-Instanz
// Route für das Überprüfen der Bambu-Instanz
server.on("/api/bambu", HTTP_GET, [](AsyncWebServerRequest *request){
if (!request->hasParam("bambu_ip") || !request->hasParam("bambu_serialnr") || !request->hasParam("bambu_accesscode")) {
request->send(400, "application/json", "{\"success\": false, \"error\": \"Missing parameter\"}");