feat: add functionality to remove Bambu credentials and update API handling
This commit is contained in:
		| @@ -38,6 +38,32 @@ int ams_count = 0; | ||||
| String amsJsonData;  // Speichert das fertige JSON für WebSocket-Clients | ||||
| AMSData ams_data[MAX_AMS];  // Definition des Arrays; | ||||
|  | ||||
| bool removeBambuCredentials() { | ||||
|     if (BambuMqttTask) { | ||||
|         vTaskDelete(BambuMqttTask); | ||||
|     } | ||||
|      | ||||
|     if (!removeJsonValue("/bambu_credentials.json")) { | ||||
|         Serial.println("Fehler beim Löschen der Bambu-Credentials."); | ||||
|         return false; | ||||
|     } | ||||
|     // Löschen der globalen Variablen | ||||
|     g_bambu_ip = ""; | ||||
|     g_bambu_accesscode = ""; | ||||
|     g_bambu_serialnr = ""; | ||||
|     bambu_ip = nullptr; | ||||
|     bambu_accesscode = nullptr; | ||||
|     bambu_serialnr = nullptr; | ||||
|     autoSendToBambu = false; | ||||
|     autoSetToBambuSpoolId = 0; | ||||
|     ams_count = 0; | ||||
|     amsJsonData = ""; | ||||
|  | ||||
|     bambuDisabled = true; | ||||
|  | ||||
|     return true; | ||||
| } | ||||
|  | ||||
| bool saveBambuCredentials(const String& ip, const String& serialnr, const String& accesscode, bool autoSend, const String& autoSendTime) { | ||||
|     if (BambuMqttTask) { | ||||
|         vTaskDelete(BambuMqttTask); | ||||
|   | ||||
| @@ -32,6 +32,7 @@ extern bool autoSendToBambu; | ||||
| extern int autoSetToBambuSpoolId; | ||||
| extern bool bambuDisabled; | ||||
|  | ||||
| bool removeBambuCredentials(); | ||||
| bool loadBambuCredentials(); | ||||
| bool saveBambuCredentials(const String& bambu_ip, const String& bambu_serialnr, const String& bambu_accesscode, const bool autoSend, const String& autoSendTime); | ||||
| bool setupMqtt(); | ||||
|   | ||||
| @@ -1,6 +1,20 @@ | ||||
| #include "commonFS.h" | ||||
| #include <LittleFS.h> | ||||
|  | ||||
| bool removeJsonValue(const char* filename) { | ||||
|     File file = LittleFS.open(filename, "r"); | ||||
|     if (!file) { | ||||
|         return true; | ||||
|     } | ||||
|     file.close(); | ||||
|     if (!LittleFS.remove(filename)) { | ||||
|         Serial.print("Fehler beim Löschen der Datei: "); | ||||
|         Serial.println(filename); | ||||
|         return false; | ||||
|     } | ||||
|     return true; | ||||
| } | ||||
|  | ||||
| bool saveJsonValue(const char* filename, const JsonDocument& doc) { | ||||
|     File file = LittleFS.open(filename, "w"); | ||||
|     if (!file) { | ||||
|   | ||||
| @@ -5,6 +5,7 @@ | ||||
| #include <ArduinoJson.h> | ||||
| #include <LittleFS.h> | ||||
|  | ||||
| bool removeJsonValue(const char* filename); | ||||
| bool saveJsonValue(const char* filename, const JsonDocument& doc); | ||||
| bool loadJsonValue(const char* filename, JsonDocument& doc); | ||||
| void initializeFileSystem(); | ||||
|   | ||||
| @@ -313,6 +313,15 @@ void setupWebserver(AsyncWebServer &server) { | ||||
|  | ||||
|     // Route für das Überprüfen der Bambu-Instanz | ||||
|     server.on("/api/bambu", HTTP_GET, [](AsyncWebServerRequest *request){ | ||||
|         if (request->hasParam("remove")) { | ||||
|             if (removeBambuCredentials()) { | ||||
|                 request->send(200, "application/json", "{\"success\": true}"); | ||||
|             } else { | ||||
|                 request->send(500, "application/json", "{\"success\": false, \"error\": \"Fehler beim Löschen der Bambu-Credentials\"}"); | ||||
|             } | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         if (!request->hasParam("bambu_ip") || !request->hasParam("bambu_serialnr") || !request->hasParam("bambu_accesscode")) { | ||||
|             request->send(400, "application/json", "{\"success\": false, \"error\": \"Missing parameter\"}"); | ||||
|             return; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user