From 65319ed07e251e53d2e521df80bfd4b1e7e8556c Mon Sep 17 00:00:00 2001 From: helgeerbe Date: Thu, 4 Jan 2024 15:38:28 +0100 Subject: [PATCH] log if memory allocation for live view fails Explained in #591 --- src/WebApi_ws_live.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/WebApi_ws_live.cpp b/src/WebApi_ws_live.cpp index 20308d779..f3a427292 100644 --- a/src/WebApi_ws_live.cpp +++ b/src/WebApi_ws_live.cpp @@ -68,6 +68,14 @@ void WebApiWsLiveClass::loop() try { std::lock_guard lock(_mutex); DynamicJsonDocument root(4200 * INV_MAX_COUNT); // TODO(helge) check if this calculation is correct + + // TODO(helge) temporary dump of memory usage if allocation of DynamicJsonDocument fails (will be fixed in upstream repo) + if (root.capacity() == 0) { + MessageOutput.printf("Calling /api/livedata/status has temporarily run out of resources. Reason: Alloc memory for DynamicJsonDocument failed (FreeHeap = %d, MaxAllocHeap = %d, MinFreeHeap = %d).\r\n", ESP.getFreeHeap(), ESP.getMaxAllocHeap(), ESP.getMinFreeHeap()); + _lastWsPublish = millis(); + return; + } + JsonVariant var = root; generateJsonResponse(var);