From 43591ee52daee05d1f007270967d9fb8a6e84051 Mon Sep 17 00:00:00 2001 From: Bernhard Suttner Date: Mon, 1 Apr 2024 19:00:38 +0200 Subject: [PATCH] Add Key/Value fetch method --- README.md | 17 +++++++++++++++++ src/main.cpp | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/README.md b/README.md index 8a65b8a..e0d2ebe 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,23 @@ Receive: decoded: `,,,,,` +### Fetch actual Values and State in key=value pair + +This includes the "Status" as an Integer Value, too. + +`http:/fetchkv` + +Receive: +``` +Imax=16 A +ActPower=11 kW +Status=C2 +IntStatus=194 +ActWork=0.92 kW/h +SumWork=2926 W/h +ChargeTime=00:15:02 +``` + ### Set value Imax `http:/fetch?imax=xx` (xx= 6,8,10,12,14,16) diff --git a/src/main.cpp b/src/main.cpp index 9164981..47aa133 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -833,6 +833,13 @@ static String readString(File s) return ret; } +int getIntStatus() +{ + long intValue = strtol(ABL_rx_status.c_str(), NULL, 16); + return intValue; +} + + // -------------------- WEBSERVER ---------------------------------------------- // ----------------------------------------------------------------------------- // @@ -1066,6 +1073,19 @@ void initWebServer() //debug_println("server.on /fetch: "+ s); }); + // fetch GET + server.on("/fetchkv", HTTP_GET, [](AsyncWebServerRequest *request) + { + String s = "Imax=" + String(ABL_rx_Ipwm) + " A \n" + + "ActPower=" + String(ABL_rx_kW) + " kW\n" + + "Status=" + String(ABL_rx_status) + "\n" + + "IntStatus=" + String(getIntStatus()) + "\n" + + "ActWork=" + String(ABL_rx_Wh/1000.0) + " kW/h\n" + + "SumWork=" + String(ABL_Wh_Sum_akt) + " W/h\n" + + "ChargeTime=" + String(ABL_sChargeTime) + "\n"; + request->send(200, "text/plain", s); + }); + // config.txt GET server.on("/config.txt", HTTP_GET, [](AsyncWebServerRequest *request){ request->send(SPIFFS, "/config.txt", "text/html", false);