From 5778bee9b27470be8fe1c0173ebc676b86a3c3c2 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 29 Jan 2023 17:56:43 +0200 Subject: [PATCH] added test routines for config export --- include/NetTransport.h | 1 + src/HTTPPostSystem.c | 11 +++++++++++ src/HTTPPrintSystem.c | 24 ++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/include/NetTransport.h b/include/NetTransport.h index 16b4ed5..3e2913a 100644 --- a/include/NetTransport.h +++ b/include/NetTransport.h @@ -111,5 +111,6 @@ uint32_t GetUpTime(void); void RegEthReset(void (*eth_rst)(uint8_t level)); void RegGSMReset(void (*gsm_rst)(uint8_t level)); +void GenerateSystemSettingsJSONFile(void); #endif /* MAIN_INCLUDE_NETTRANSPORT_H_ */ diff --git a/src/HTTPPostSystem.c b/src/HTTPPostSystem.c index 582213e..20b9eda 100644 --- a/src/HTTPPostSystem.c +++ b/src/HTTPPostSystem.c @@ -224,6 +224,16 @@ static HTTP_IO_RESULT HTTPPostAdaptersSettings(httpd_req_t *req, char *PostData) } } + if (httpd_query_key_value(PostData, "wifisave", tmp, 4) == ESP_OK) + { + if (!strcmp(tmp, (const char*) "prs")) + { + WriteNVSSysConfig(GetSysConf()); + memcpy(PostData, "/reboot.html", sizeof "/reboot.html"); + return HTTP_IO_REDIRECT; + } + } + if (httpd_query_key_value(PostData, "save", tmp, 5) == ESP_OK || httpd_query_key_value(PostData, "apply", tmp, 5) == ESP_OK) { @@ -512,6 +522,7 @@ static HTTP_IO_RESULT HTTPPostSystemSettings(httpd_req_t *req, char *PostData) } else if (!strcmp(tmp, (const char*) "10")) { + GenerateSystemSettingsJSONFile(); return HTTP_IO_DONE_NOREFRESH; } diff --git a/src/HTTPPrintSystem.c b/src/HTTPPrintSystem.c index 4d94fee..8edb679 100644 --- a/src/HTTPPrintSystem.c +++ b/src/HTTPPrintSystem.c @@ -29,6 +29,7 @@ #include "esp_ota_ops.h" #include "ROMFS.h" #include "esp_idf_version.h" +#include "jWrite.h" static const char *TAG = "HTTPServerPrint"; @@ -886,3 +887,26 @@ int HTTPPrint(httpd_req_t *req, char *buf, char *var) return dLen; } + + +void GenerateSystemSettingsJSONFile(void) +{ + char *buf = malloc(2048); + if(!buf) return; + + jwOpen(buf, 2048, JW_OBJECT, JW_PRETTY); + for (int i = 0; i < (sizeof(HANDLERS_ARRAY) / sizeof(HANDLERS_ARRAY[0])); ++i) + { + char val[18]; + val[0] = 0x00; + strcat(val, "~"); + strcat(val, HANDLERS_ARRAY[i].tag); + strcat(val, "~"); + jwObj_string(HANDLERS_ARRAY[i].tag, val); + } + jwEnd(); + jwClose(); + ESP_LOGI(TAG, "%s", buf); + free(buf); +} +