Feature: First version of GridProfile Parser which shows all values contained in the profile.

This commit is contained in:
Thomas Basler
2023-12-11 14:58:17 +01:00
parent f851acab4d
commit 06651f365a
11 changed files with 491 additions and 18 deletions

View File

@@ -14,6 +14,7 @@ void WebApiGridProfileClass::init(AsyncWebServer* server)
_server = server;
_server->on("/api/gridprofile/status", HTTP_GET, std::bind(&WebApiGridProfileClass::onGridProfileStatus, this, _1));
_server->on("/api/gridprofile/rawdata", HTTP_GET, std::bind(&WebApiGridProfileClass::onGridProfileRawdata, this, _1));
}
void WebApiGridProfileClass::loop()
@@ -26,6 +27,50 @@ void WebApiGridProfileClass::onGridProfileStatus(AsyncWebServerRequest* request)
return;
}
AsyncJsonResponse* response = new AsyncJsonResponse(false, 8192);
JsonObject root = response->getRoot();
uint64_t serial = 0;
if (request->hasParam("inv")) {
String s = request->getParam("inv")->value();
serial = strtoll(s.c_str(), NULL, 16);
}
auto inv = Hoymiles.getInverterBySerial(serial);
if (inv != nullptr) {
root["name"] = inv->GridProfile()->getProfileName();
root["version"] = inv->GridProfile()->getProfileVersion();
auto jsonSections = root.createNestedArray("sections");
auto profSections = inv->GridProfile()->getProfile();
for (auto &profSection : profSections) {
auto jsonSection = jsonSections.createNestedObject();
jsonSection["name"] = profSection.SectionName;
auto jsonItems = jsonSection.createNestedArray("items");
for (auto &profItem : profSection.items) {
auto jsonItem = jsonItems.createNestedObject();
jsonItem["n"] = profItem.Name;
jsonItem["u"] = profItem.Unit;
jsonItem["v"] = profItem.Value;
}
}
}
response->setLength();
request->send(response);
}
void WebApiGridProfileClass::onGridProfileRawdata(AsyncWebServerRequest* request)
{
if (!WebApi.checkCredentialsReadonly(request)) {
return;
}
AsyncJsonResponse* response = new AsyncJsonResponse(false, 4096);
JsonObject root = response->getRoot();
@@ -42,9 +87,6 @@ void WebApiGridProfileClass::onGridProfileStatus(AsyncWebServerRequest* request)
auto data = inv->GridProfile()->getRawData();
copyArray(&data[0], data.size(), raw);
root["name"] = inv->GridProfile()->getProfileName();
root["version"] = inv->GridProfile()->getProfileVersion();
}
response->setLength();