This commit is contained in:
2024-12-26 21:47:42 +01:00
parent 0d798086ca
commit c734884021

View File

@@ -1,7 +1,10 @@
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <LiquidCrystal_I2C.h>
#include <settings.h>
//#include <settings.h>
#include <settings-my-ignore.h>
#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);
}
}
}