From 38b68aecfc6c3088c409f8bb12649afe4df3cb6b Mon Sep 17 00:00:00 2001 From: Manuel Weiser Date: Fri, 21 Feb 2025 17:11:48 +0100 Subject: [PATCH] docs: update JSON field type checks from JsonObject to String for improved validation --- src/api.cpp | 8 ++++---- src/bambu.cpp | 10 +++++----- src/website.cpp | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/api.cpp b/src/api.cpp index ba9d6a7..e3b13ef 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -186,7 +186,7 @@ bool updateSpoolTagId(String uidString, const char* payload) { } // Überprüfe, ob die erforderlichen Felder vorhanden sind - if (!doc["sm_id"].is() || doc["sm_id"].as() == "") { + if (!doc["sm_id"].is() || doc["sm_id"].as() == "") { Serial.println("Keine Spoolman-ID gefunden."); return false; } @@ -368,7 +368,7 @@ bool checkSpoolmanExtraFields() { for (uint8_t s = 0; s < extraLength; s++) { bool found = false; for (JsonObject field : doc.as()) { - if (field["key"].is() && field["key"] == extraFields[s]) { + if (field["key"].is() && field["key"] == extraFields[s]) { Serial.println("Feld gefunden: " + extraFields[s]); found = true; break; @@ -430,7 +430,7 @@ bool checkSpoolmanInstance(const String& url) { String payload = http.getString(); JsonDocument doc; DeserializationError error = deserializeJson(doc, payload); - if (!error && doc["status"].is()) { + if (!error && doc["status"].is()) { const char* status = doc["status"]; http.end(); @@ -469,7 +469,7 @@ bool saveSpoolmanUrl(const String& url) { String loadSpoolmanUrl() { JsonDocument doc; - if (loadJsonValue("/spoolman_url.json", doc) && doc["url"].is()) { + if (loadJsonValue("/spoolman_url.json", doc) && doc["url"].is()) { return doc["url"].as(); } Serial.println("Keine gültige Spoolman-URL gefunden."); diff --git a/src/bambu.cpp b/src/bambu.cpp index b1a2bde..4583c78 100644 --- a/src/bambu.cpp +++ b/src/bambu.cpp @@ -58,7 +58,7 @@ bool saveBambuCredentials(const String& ip, const String& serialnr, const String bool loadBambuCredentials() { JsonDocument doc; - if (loadJsonValue("/bambu_credentials.json", doc) && doc["bambu_ip"].is()) { + if (loadJsonValue("/bambu_credentials.json", doc) && doc["bambu_ip"].is()) { // Temporäre Strings für die Werte String ip = doc["bambu_ip"].as(); String code = doc["bambu_accesscode"].as(); @@ -270,9 +270,9 @@ void mqtt_callback(char* topic, byte* payload, unsigned int length) { } // Prüfen, ob "print->upgrade_state" und "print.ams.ams" existieren - if (doc["print"]["upgrade_state"].is()) { + if (doc["print"]["upgrade_state"].is()) { // Prüfen ob AMS-Daten vorhanden sind - if (!doc["print"]["ams"].is() || !doc["print"]["ams"]["ams"].is()) { + if (!doc["print"]["ams"].is() || !doc["print"]["ams"]["ams"].is()) { return; } @@ -315,7 +315,7 @@ void mqtt_callback(char* topic, byte* payload, unsigned int length) { } // Prüfe die externe Spule - if (!hasChanges && doc["print"]["vt_tray"].is()) { + if (!hasChanges && doc["print"]["vt_tray"].is()) { JsonObject vtTray = doc["print"]["vt_tray"]; bool foundExternal = false; @@ -363,7 +363,7 @@ void mqtt_callback(char* topic, byte* payload, unsigned int length) { ams_count = amsArray.size(); // Wenn externe Spule vorhanden, füge sie hinzu - if (doc["print"]["vt_tray"].is()) { + if (doc["print"]["vt_tray"].is()) { JsonObject vtTray = doc["print"]["vt_tray"]; int extIdx = ams_count; // Index für externe Spule ams_data[extIdx].ams_id = 255; // Spezielle ID für externe Spule diff --git a/src/website.cpp b/src/website.cpp index 289051c..d5f452f 100644 --- a/src/website.cpp +++ b/src/website.cpp @@ -49,7 +49,7 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp } else if (doc["type"] == "writeNfcTag") { - if (doc["payload"].is()) { + if (doc["payload"].is()) { // Versuche NFC-Daten zu schreiben String payloadString; serializeJson(doc["payload"], payloadString); @@ -235,7 +235,7 @@ void setupWebserver(AsyncWebServer &server) { html.replace("{{spoolmanUrl}}", spoolmanUrl); JsonDocument doc; - if (loadJsonValue("/bambu_credentials.json", doc) && doc["bambu_ip"].is()) { + if (loadJsonValue("/bambu_credentials.json", doc) && doc["bambu_ip"].is()) { String bambuIp = doc["bambu_ip"].as(); String bambuSerial = doc["bambu_serialnr"].as(); String bambuCode = doc["bambu_accesscode"].as();