From c7348840215d6ea35e79ef114d3cfccaadb5bb78 Mon Sep 17 00:00:00 2001 From: Thorsten Date: Thu, 26 Dec 2024 21:47:42 +0100 Subject: [PATCH] clean --- src/main.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 42350a3..fadd084 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,10 @@ #include #include #include -#include +//#include +#include + + #define BUTTON_PIN D3 // GPIO-Pin verbunden mit Taster (D3 entspricht GPIO0) @@ -104,6 +107,10 @@ void extractTasmotaValues(const String& url, String values[5]) { WiFiClient client; HTTPClient http; + for (int i = 0; i < 5; i++) { + values[i] = "?"; // Standardwert, falls Tasmota Gerät nicht antwortet + } + if (http.begin(client, url)) { int httpResponseCode = http.GET(); @@ -116,7 +123,7 @@ void extractTasmotaValues(const String& url, String values[5]) { // Werte initialisieren for (int i = 0; i < 5; i++) { - values[i] = ""; // Standardwert, falls Key nicht gefunden wird + values[i] = "?"; // Standardwert, falls Key nicht gefunden wird int keyIndex = response.indexOf("\"" + keys[i] + "\":"); if (keyIndex != -1) { int valueStart = keyIndex + keys[i].length() + 3; // Position nach dem ":" @@ -132,7 +139,8 @@ void extractTasmotaValues(const String& url, String values[5]) { } } else { Serial.println("HTTP Fehler: " + String(httpResponseCode)); - } + + } http.end(); } else { Serial.println("Verbindung zur URL fehlgeschlagen: " + url); @@ -280,8 +288,6 @@ void loop() { handleButtonPress(); - //Serial.print("."); - if (WiFi.status() != WL_CONNECTED && !reconnecting) { reconnecting = true; connectToWiFi(); @@ -292,12 +298,10 @@ void loop() { if (millis() - lastUpdateTime >= refreshRate) { lastUpdateTime = millis(); - extractTasmotaValues("http://" + ip_netzbezug + "/cm?cmnd=Status%208", ip_netzbezug_values); - switch (currentMode) { - case 0: - extractTasmotaValues("http://" + ip_erzeugung + "/cm?cmnd=Status%208", ip_erzeugung_values); + if (currentMode == 0) { + extractTasmotaValues("http://" + ip_erzeugung + "/cm?cmnd=Status%208", ip_erzeugung_values); } } }