From e23e1617cf402d548a774e1712fd69591fa1fdfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Nidecki?= Date: Mon, 14 Jun 2021 17:46:14 +0200 Subject: [PATCH] Allocate JsonDocument in PSRAM --- lib/PSRAMJsonDocument/PSRAMJsonDocument.h | 27 +++++++++++++++++++++++ src/taskWebServer.cpp | 14 +++++++----- 2 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 lib/PSRAMJsonDocument/PSRAMJsonDocument.h diff --git a/lib/PSRAMJsonDocument/PSRAMJsonDocument.h b/lib/PSRAMJsonDocument/PSRAMJsonDocument.h new file mode 100644 index 0000000..da0087b --- /dev/null +++ b/lib/PSRAMJsonDocument/PSRAMJsonDocument.h @@ -0,0 +1,27 @@ +// +// Created by Admin on 14.06.2021. +// + +#ifndef TTGO_T_BEAM_LORA_APRS_PSRAMJSONDOCUMENT_H +#define TTGO_T_BEAM_LORA_APRS_PSRAMJSONDOCUMENT_H + +#include + +struct SpiRamAllocator { + void* allocate(size_t size) { + return heap_caps_malloc(size, MALLOC_CAP_SPIRAM); + } + + void deallocate(void* pointer) { + heap_caps_free(pointer); + } + + void* reallocate(void* ptr, size_t new_size) { + return heap_caps_realloc(ptr, new_size, MALLOC_CAP_SPIRAM); + } +}; + +using PSRAMJsonDocument = BasicJsonDocument; + + +#endif //TTGO_T_BEAM_LORA_APRS_PSRAMJSONDOCUMENT_H diff --git a/src/taskWebServer.cpp b/src/taskWebServer.cpp index 712103b..d0dca3a 100644 --- a/src/taskWebServer.cpp +++ b/src/taskWebServer.cpp @@ -2,6 +2,7 @@ #include "taskWebServer.h" #include "preference_storage.h" #include "syslog_log.h" +#include "PSRAMJsonDocument.h" #include #include @@ -17,7 +18,7 @@ extern const char web_js_js_end[] asm("_binary_data_embed_js_js_out_end"); QueueHandle_t webListReceivedQueue = nullptr; std::list receivedPackets; -const int MAX_RECEIVED_LIST_SIZE = 10; +const int MAX_RECEIVED_LIST_SIZE = 50; String apSSID = ""; String apPassword = "xxxxxxxxxx"; @@ -129,11 +130,10 @@ void handle_Reboot() { void handle_Shutdown() { #ifdef T_BEAM_V1_0 - server.sendHeader("Location", "/"); - server.send(302,"text/html", ""); + server.send(200,"text/html", "Shutdown"); axp.shutdown(); #else - server.send(302,"text/html", "Not supported"); + server.send(404,"text/html", "Not supported"); #endif } @@ -169,14 +169,16 @@ void handle_Cfg() { jsonData += jsonLineFromPreferenceInt(PREF_DEV_AUTO_SHUT_PRESET); jsonData += jsonLineFromInt("FreeHeap", ESP.getFreeHeap()); jsonData += jsonLineFromInt("HeapSize", ESP.getHeapSize()); - jsonData += jsonLineFromInt("FreeSketchSpace", ESP.getFreeSketchSpace(), true); + jsonData += jsonLineFromInt("FreeSketchSpace", ESP.getFreeSketchSpace()); + jsonData += jsonLineFromInt("PSRAMSize", ESP.getPsramSize()); + jsonData += jsonLineFromInt("PSRAMFree", ESP.getFreePsram(), true); jsonData += "}"; server.send(200,"application/json", jsonData); } void handle_ReceivedList() { - DynamicJsonDocument doc(MAX_RECEIVED_LIST_SIZE * 500); + PSRAMJsonDocument doc(MAX_RECEIVED_LIST_SIZE * 1000); JsonObject root = doc.to(); auto received = root.createNestedArray("received"); for (auto element: receivedPackets){