From a20c2b856490de4d43ce13302b4b1accc41fc584 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Mon, 16 Nov 2020 18:47:09 +0300 Subject: [PATCH] Save date to flash added --- data/set.device.json | 2 +- include/Global.h | 1 + include/Utils/JsonUtils.h | 2 +- src/Global.cpp | 1 + src/Init.cpp | 6 ++---- src/MqttClient.cpp | 2 +- src/Utils/JsonUtils.cpp | 6 ++---- src/Web.cpp | 1 + src/WebServer.cpp | 4 ++++ src/items/vButtonOut.cpp | 8 ++++---- src/items/vInput.cpp | 8 ++++---- src/items/vLogging.cpp | 4 ++-- 12 files changed, 24 insertions(+), 21 deletions(-) diff --git a/data/set.device.json b/data/set.device.json index b45d6c71..8eb0b1e3 100644 --- a/data/set.device.json +++ b/data/set.device.json @@ -160,7 +160,7 @@ }, { "type": "button", - "title": "Очистить графики и сбросить введенные данные", + "title": "Очистить графики и введенные данные", "action": "/set?cleanlog", "class": "btn btn-block btn-default" }, diff --git a/include/Global.h b/include/Global.h index fd0205f2..d00d8266 100644 --- a/include/Global.h +++ b/include/Global.h @@ -52,6 +52,7 @@ extern boolean telegramInitBeen; // Json extern String configSetupJson; //все настройки extern String configLiveJson; //все данные с датчиков (связан с mqtt) +extern String configStoreJson; //все данные которые должны сохраняться extern String configOptionJson; //для трансфера // Mqtt diff --git a/include/Utils/JsonUtils.h b/include/Utils/JsonUtils.h index 4f60503a..2b19dcc5 100644 --- a/include/Utils/JsonUtils.h +++ b/include/Utils/JsonUtils.h @@ -18,4 +18,4 @@ String jsonWriteBool(String& json, String name, boolean value); void saveConfig(); -void saveLive(); \ No newline at end of file +void saveStore(); \ No newline at end of file diff --git a/src/Global.cpp b/src/Global.cpp index d8facc43..9b41fb67 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -23,6 +23,7 @@ boolean telegramInitBeen = false; // Json String configSetupJson = "{}"; String configLiveJson = "{}"; +String configStoreJson = "{}"; String configOptionJson = "{}"; // Mqtt diff --git a/src/Init.cpp b/src/Init.cpp index 36d98c21..08969c88 100644 --- a/src/Init.cpp +++ b/src/Init.cpp @@ -12,10 +12,8 @@ void loadConfig() { configSetupJson = readFile("config.json", 4096); configSetupJson.replace("\r\n", ""); -#ifdef SAVE_SETTINGS_TO_FLASH - configLiveJson = readFile("live.json", 4096); - configLiveJson.replace("\r\n", ""); -#endif + configStoreJson = readFile("store.json", 4096); + configStoreJson.replace("\r\n", ""); jsonWriteStr(configSetupJson, "chipID", chipId); jsonWriteInt(configSetupJson, "firmware_version", FIRMWARE_VERSION); diff --git a/src/MqttClient.cpp b/src/MqttClient.cpp index cdd18448..38844fb0 100644 --- a/src/MqttClient.cpp +++ b/src/MqttClient.cpp @@ -232,7 +232,7 @@ void publishWidgets() { void publishState() { // берет строку json и ключи превращает в топики а значения колючей в них посылает - String str = configLiveJson; + String str = configLiveJson + "," + configStoreJson; str.replace("{", ""); str.replace("}", ""); str += ","; diff --git a/src/Utils/JsonUtils.cpp b/src/Utils/JsonUtils.cpp index fad6c937..ca70c082 100644 --- a/src/Utils/JsonUtils.cpp +++ b/src/Utils/JsonUtils.cpp @@ -55,8 +55,6 @@ void saveConfig() { writeFile(String("config.json"), configSetupJson); } -void saveLive() { -#ifdef SAVE_SETTINGS_TO_FLASH - writeFile(String("live.json"), configLiveJson); -#endif +void saveStore() { + writeFile(String("store.json"), configStoreJson); } \ No newline at end of file diff --git a/src/Web.cpp b/src/Web.cpp index 9b2a84e0..3c30b59d 100644 --- a/src/Web.cpp +++ b/src/Web.cpp @@ -36,6 +36,7 @@ void web_init() { if (request->hasArg("delAllItems")) { delAllItems(); + cleanLogAndData(); request->redirect("/?set.device"); } diff --git a/src/WebServer.cpp b/src/WebServer.cpp index 0cd23843..9a4611f4 100644 --- a/src/WebServer.cpp +++ b/src/WebServer.cpp @@ -49,6 +49,10 @@ void init() { request->send(200, "application/json", configLiveJson); }); + server.on("/config.store.json", HTTP_GET, [](AsyncWebServerRequest *request) { + request->send(200, "application/json", configStoreJson); + }); + // данные не являющиеся событиями server.on("/config.option.json", HTTP_GET, [](AsyncWebServerRequest *request) { request->send(200, "application/json", configOptionJson); diff --git a/src/items/vButtonOut.cpp b/src/items/vButtonOut.cpp index bb4759ec..a45b7c9f 100644 --- a/src/items/vButtonOut.cpp +++ b/src/items/vButtonOut.cpp @@ -5,13 +5,13 @@ #include "Class/LineParsing.h" #include "Global.h" #include "BufferExecute.h" - +//this class save date to flash ButtonOut::ButtonOut(unsigned int pin, boolean inv, String key) { _pin = pin; _inv = inv; _key = key; pinMode(_pin, OUTPUT); - int state = jsonReadInt(configLiveJson, key); + int state = jsonReadInt(configStoreJson, key); this->execute(String(state)); } ButtonOut::~ButtonOut() {} @@ -30,8 +30,8 @@ void ButtonOut::execute(String state) { } } eventGen2(_key, state); - jsonWriteInt(configLiveJson, _key, state.toInt()); - saveLive(); + jsonWriteInt(configStoreJson, _key, state.toInt()); + saveStore(); publishStatus(_key, state); } diff --git a/src/items/vInput.cpp b/src/items/vInput.cpp index 7a71b472..76589d94 100644 --- a/src/items/vInput.cpp +++ b/src/items/vInput.cpp @@ -5,10 +5,10 @@ #include "Class/LineParsing.h" #include "Global.h" #include "BufferExecute.h" - +//this class save date to flash Input::Input(String key, String widget) { _key = key; - String value = jsonReadStr(configLiveJson, key); + String value = jsonReadStr(configStoreJson, key); if (value == "") { if (widget.indexOf("Digit") != -1) { @@ -25,8 +25,8 @@ Input::~Input() {} void Input::execute(String value) { eventGen2(_key, value); - jsonWriteStr(configLiveJson, _key, value); - saveLive(); + jsonWriteStr(configStoreJson, _key, value); + saveStore(); publishStatus(_key, value); } diff --git a/src/items/vLogging.cpp b/src/items/vLogging.cpp index 473fe5b0..2958cf1c 100644 --- a/src/items/vLogging.cpp +++ b/src/items/vLogging.cpp @@ -120,7 +120,7 @@ void cleanLogAndData() { SerialPrint("I", "System", fname); removeFile("logs/" + fname); } - removeFile("live.json"); - configLiveJson = ""; #endif + removeFile("store.json"); + configStoreJson = ""; }