Allocate JsonDocument in PSRAM

pull/45/head
Łukasz Nidecki 2021-06-14 17:46:14 +02:00
rodzic 1a2771ed26
commit e23e1617cf
2 zmienionych plików z 35 dodań i 6 usunięć

Wyświetl plik

@ -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 <ArduinoJson.h>
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<SpiRamAllocator>;
#endif //TTGO_T_BEAM_LORA_APRS_PSRAMJSONDOCUMENT_H

Wyświetl plik

@ -2,6 +2,7 @@
#include "taskWebServer.h"
#include "preference_storage.h"
#include "syslog_log.h"
#include "PSRAMJsonDocument.h"
#include <time.h>
#include <ArduinoJson.h>
@ -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 <tReceivedPacketData*> 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<JsonObject>();
auto received = root.createNestedArray("received");
for (auto element: receivedPackets){