diff --git a/platformio.ini b/platformio.ini index 2e0a7fe..b3eac91 100644 --- a/platformio.ini +++ b/platformio.ini @@ -26,7 +26,8 @@ lib_deps = Adafruit GFX Library Adafruit Unified Sensor https://github.com/SQ9MDD/AXP202X_Library.git - SparkFun u-blox Arduino Library + SparkFun u-blox Arduino Library + bblanchon/ArduinoJson build_flags = -Wl,--gc-sections,--relax -D 'KISS_PROTOCOL' diff --git a/src/taskWebServer.cpp b/src/taskWebServer.cpp index e1f2665..bcd2823 100644 --- a/src/taskWebServer.cpp +++ b/src/taskWebServer.cpp @@ -3,6 +3,8 @@ #include "preference_storage.h" #include "syslog_log.h" #include +#include + /** * @see board_build.embed_txtfiles in platformio.ini */ @@ -15,7 +17,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 = 50; +const int MAX_RECEIVED_LIST_SIZE = 10; String apSSID = ""; String apPassword = "xxxxxxxxxx"; @@ -151,24 +153,21 @@ void handle_Cfg() { } void handle_ReceivedList() { - String jsonData = "{\"received\": ["; - auto count = receivedPackets.size(); + DynamicJsonDocument doc(MAX_RECEIVED_LIST_SIZE * 500); + JsonObject root = doc.to(); + auto received = root.createNestedArray("received"); for (auto element: receivedPackets){ - jsonData += "{"; char buf[64]; strftime(buf, 64, "%Y.%m.%d %H:%M:%S", &element->rxTime); - jsonData += jsonLineFromString("time", buf); - jsonData += jsonLineFromString("packet", element->packet->c_str()); - jsonData += jsonLineFromInt("rssi", element->RSSI); - jsonData += jsonLineFromInt("snr", element->SNR, true); - jsonData += "}"; - count--; - if (count){ - jsonData += ","; - } + auto packet_data = received.createNestedObject(); + packet_data["time"] = String(buf); + packet_data["packet"] = element->packet->c_str(); + packet_data["rssi"] = element->RSSI; + packet_data["snr"] = element->SNR / 10.0f; + received.add(packet_data); } - jsonData += "]}"; - server.send(200,"application/json", jsonData); + + server.send(200,"application/json", doc.as()); } void handle_SaveAPRSCfg() {