From 10afc57b6547411c49c4311bc94fcf39f23c009e Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Mon, 8 Sep 2025 12:21:10 +0200 Subject: [PATCH] fix crash due to memory issues by using heap - dynamic json --- src/webserver.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/webserver.h b/src/webserver.h index ee58f14..01c3db7 100644 --- a/src/webserver.h +++ b/src/webserver.h @@ -9,9 +9,6 @@ AsyncWebServer server(80); namespace WebServer { - void notFound(AsyncWebServerRequest *request) { - request->send(404, "text/plain", "Not found"); - } void setup() { @@ -34,7 +31,7 @@ namespace WebServer { server.on("/commands", HTTP_GET, [](AsyncWebServerRequest *request) { AsyncResponseStream *response = request->beginResponseStream("application/json"); - StaticJsonDocument jsonResponse; + DynamicJsonDocument jsonResponse(JSON_SIZE*10); JsonArray array = jsonResponse.to(); for (auto it = Command::mapCommandIds.begin(); it != Command::mapCommandIds.end(); ++it) { StaticJsonDocument jsonDoc; @@ -46,7 +43,9 @@ namespace WebServer { request->send(response); }); - server.onNotFound(notFound); + server.onNotFound([](AsyncWebServerRequest *request) { + request->send(404, "text/plain", "Not found"); + }); server.begin(); }