Small API fix

This commit is contained in:
Djuri Baars 2023-11-19 02:23:47 +01:00
parent b195368150
commit 7ded1c16d6

View file

@ -162,11 +162,13 @@ void onApiStatus(AsyncWebServerRequest *request)
{ {
AsyncResponseStream *response = request->beginResponseStream("application/json"); AsyncResponseStream *response = request->beginResponseStream("application/json");
StaticJsonDocument<768> root = getStatusObject(); StaticJsonDocument<1024> root = getStatusObject();
JsonArray data = root.createNestedArray("data"); JsonArray data = root.createNestedArray("data");
JsonArray rendered = root.createNestedArray("rendered"); JsonArray rendered = root.createNestedArray("rendered");
String epdContent[NUM_SCREENS]; String epdContent[NUM_SCREENS];
root["leds"] = getLedStatusObject()["data"];
std::array<String, NUM_SCREENS> retEpdContent = getCurrentEpdContent(); std::array<String, NUM_SCREENS> retEpdContent = getCurrentEpdContent();
std::copy(std::begin(retEpdContent), std::end(retEpdContent), epdContent); std::copy(std::begin(retEpdContent), std::end(retEpdContent), epdContent);
@ -695,6 +697,8 @@ void onApiLightsSetColor(AsyncWebServerRequest *request)
{ {
if (request->hasParam("c")) if (request->hasParam("c"))
{ {
AsyncResponseStream *response = request->beginResponseStream("application/json");
String rgbColor = request->getParam("c")->value(); String rgbColor = request->getParam("c")->value();
if (rgbColor.compareTo("off") == 0) if (rgbColor.compareTo("off") == 0)
@ -707,7 +711,16 @@ void onApiLightsSetColor(AsyncWebServerRequest *request)
sscanf(rgbColor.c_str(), "%02x%02x%02x", &r, &g, &b); sscanf(rgbColor.c_str(), "%02x%02x%02x", &r, &g, &b);
setLights(r, g, b); setLights(r, g, b);
} }
request->send(200, "text/plain", rgbColor);
StaticJsonDocument<48> doc;
doc["result"] = rgbColor;
serializeJson(getLedStatusObject()["data"], *response);
request->send(response);
} else {
request->send(400);
} }
} }