From 58970f485e3e688d795196b421e0067d80d3b945 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Fri, 1 Dec 2023 19:51:58 +0100 Subject: [PATCH] use one allocation size for DynamicJsonDocument settings The problem was detected in configSetup() - the configuration was read only from EEPROM but not from SPI flash FS. Cleanup things and use only one allocation size for both write and read configuration operations. --- src/hasp_config.cpp | 4 ++-- src/hasp_config.h | 2 ++ src/sys/svc/hasp_http.cpp | 4 ++-- src/sys/svc/hasp_http_async.cpp | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/hasp_config.cpp b/src/hasp_config.cpp index 61811a83..9e3f5ce5 100644 --- a/src/hasp_config.cpp +++ b/src/hasp_config.cpp @@ -354,7 +354,7 @@ void configWrite() settingsChanged = F(D_CONFIG_CHANGED); /* Read Config File */ - DynamicJsonDocument doc(8 * 256); + DynamicJsonDocument doc(MAX_CONFIG_JSON_ALLOC_SIZE); LOG_TRACE(TAG_CONF, F(D_FILE_LOADING), configFile.c_str()); configRead(doc, false); LOG_INFO(TAG_CONF, F(D_FILE_LOADED), configFile.c_str()); @@ -515,7 +515,7 @@ void configWrite() void configSetup() { - DynamicJsonDocument settings(1024 + 512); + DynamicJsonDocument settings(MAX_CONFIG_JSON_ALLOC_SIZE); for(uint32_t i = 0; i < 2; i++) { if(i == 0) { diff --git a/src/hasp_config.h b/src/hasp_config.h index 3e465a95..df547408 100644 --- a/src/hasp_config.h +++ b/src/hasp_config.h @@ -8,6 +8,8 @@ #include "hasplib.h" +#define MAX_CONFIG_JSON_ALLOC_SIZE (2048) + /* ===== Default Event Processors ===== */ void configSetup(void); void configLoop(void); diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index 046c3831..d9b12158 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -561,7 +561,7 @@ static void webHandleApi() { // http://plate01/api if(!http_is_authenticated("api")) return; - DynamicJsonDocument doc(2048); + DynamicJsonDocument doc(max(MAX_CONFIG_JSON_ALLOC_SIZE, 2048)); String contentType = http_get_content_type(F(".json")); String endpoint((char*)0); endpoint = webServer.pathArg(0); @@ -1109,7 +1109,7 @@ static inline int handleFilesystemFile(String path) configFile = FPSTR(FP_HASP_CONFIG_FILE); if(path.endsWith(configFile.c_str())) { // "//config.json" is also a valid path! - DynamicJsonDocument settings(2048); + DynamicJsonDocument settings(MAX_CONFIG_JSON_ALLOC_SIZE); DeserializationError error = configParseFile(configFile, settings); if(error) return 500; // Internal Server Error diff --git a/src/sys/svc/hasp_http_async.cpp b/src/sys/svc/hasp_http_async.cpp index 13d51d20..9232cf0d 100644 --- a/src/sys/svc/hasp_http_async.cpp +++ b/src/sys/svc/hasp_http_async.cpp @@ -934,7 +934,7 @@ int handleFileRead(AsyncWebServerRequest* request, String path) if(!strncasecmp(file.name(), configFile.c_str(), configFile.length())) { file.close(); - DynamicJsonDocument settings(8 * 256); + DynamicJsonDocument settings(MAX_CONFIG_JSON_ALLOC_SIZE); DeserializationError error = configParseFile(configFile, settings); if(error) return 500; // Internal Server Error