mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
Avoid 507, reduce buffer stepwise until it fits
This commit is contained in:
@@ -101,14 +101,12 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject & input) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// output json buffer
|
// output json buffer
|
||||||
auto * response = new PrettyAsyncJsonResponse(false, EMSESP_JSON_SIZE_XXLARGE_DYN);
|
size_t buffer = EMSESP_JSON_SIZE_XXLARGE_DYN;
|
||||||
if (!response->getSize()) {
|
auto * response = new PrettyAsyncJsonResponse(false, buffer);
|
||||||
|
while (!response->getSize()) {
|
||||||
delete response;
|
delete response;
|
||||||
response = new PrettyAsyncJsonResponse(false, 256);
|
buffer -= 1024;
|
||||||
response->setCode(507); // Insufficient Storage
|
response = new PrettyAsyncJsonResponse(false, buffer);
|
||||||
response->setLength();
|
|
||||||
request->send(response);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
JsonObject output = response->getRoot();
|
JsonObject output = response->getRoot();
|
||||||
|
|
||||||
|
|||||||
@@ -200,14 +200,12 @@ void WebCustomizationService::devices(AsyncWebServerRequest * request) {
|
|||||||
// send back list of device entities
|
// send back list of device entities
|
||||||
void WebCustomizationService::device_entities(AsyncWebServerRequest * request, JsonVariant & json) {
|
void WebCustomizationService::device_entities(AsyncWebServerRequest * request, JsonVariant & json) {
|
||||||
if (json.is<JsonObject>()) {
|
if (json.is<JsonObject>()) {
|
||||||
auto * response = new MsgpackAsyncJsonResponse(true, EMSESP_JSON_SIZE_XXXLARGE_DYN);
|
size_t buffer = EMSESP_JSON_SIZE_XXXLARGE_DYN;
|
||||||
if (!response->getSize()) {
|
auto * response = new PrettyAsyncJsonResponse(true, buffer);
|
||||||
|
while (!response->getSize()) {
|
||||||
delete response;
|
delete response;
|
||||||
response = new MsgpackAsyncJsonResponse(true, 256);
|
buffer -= 1024;
|
||||||
response->setCode(507); // Insufficient Storage
|
response = new PrettyAsyncJsonResponse(true, buffer);
|
||||||
response->setLength();
|
|
||||||
request->send(response);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||||
if (emsdevice->unique_id() == json["id"]) {
|
if (emsdevice->unique_id() == json["id"]) {
|
||||||
|
|||||||
@@ -165,14 +165,12 @@ void WebDataService::sensor_data(AsyncWebServerRequest * request) {
|
|||||||
// Compresses the JSON using MsgPack https://msgpack.org/index.html
|
// Compresses the JSON using MsgPack https://msgpack.org/index.html
|
||||||
void WebDataService::device_data(AsyncWebServerRequest * request, JsonVariant & json) {
|
void WebDataService::device_data(AsyncWebServerRequest * request, JsonVariant & json) {
|
||||||
if (json.is<JsonObject>()) {
|
if (json.is<JsonObject>()) {
|
||||||
auto * response = new MsgpackAsyncJsonResponse(false, EMSESP_JSON_SIZE_XXXLARGE_DYN);
|
size_t buffer = EMSESP_JSON_SIZE_XXXLARGE_DYN;
|
||||||
if (!response->getSize()) {
|
auto * response = new PrettyAsyncJsonResponse(false, buffer);
|
||||||
|
while (!response->getSize()) {
|
||||||
delete response;
|
delete response;
|
||||||
response = new MsgpackAsyncJsonResponse(false, 256);
|
buffer -= 1024;
|
||||||
response->setCode(507); // Insufficient Storage
|
response = new PrettyAsyncJsonResponse(false, buffer);
|
||||||
response->setLength();
|
|
||||||
request->send(response);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||||
if (emsdevice->unique_id() == json["id"]) {
|
if (emsdevice->unique_id() == json["id"]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user