Save date to flash added

This commit is contained in:
Dmitry Borisenko
2020-11-16 18:47:09 +03:00
parent 3c3a4a33ca
commit a20c2b8564
12 changed files with 24 additions and 21 deletions

View File

@@ -23,6 +23,7 @@ boolean telegramInitBeen = false;
// Json
String configSetupJson = "{}";
String configLiveJson = "{}";
String configStoreJson = "{}";
String configOptionJson = "{}";
// Mqtt

View File

@@ -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);

View File

@@ -232,7 +232,7 @@ void publishWidgets() {
void publishState() {
// берет строку json и ключи превращает в топики а значения колючей в них посылает
String str = configLiveJson;
String str = configLiveJson + "," + configStoreJson;
str.replace("{", "");
str.replace("}", "");
str += ",";

View File

@@ -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);
}

View File

@@ -36,6 +36,7 @@ void web_init() {
if (request->hasArg("delAllItems")) {
delAllItems();
cleanLogAndData();
request->redirect("/?set.device");
}

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -120,7 +120,7 @@ void cleanLogAndData() {
SerialPrint("I", "System", fname);
removeFile("logs/" + fname);
}
removeFile("live.json");
configLiveJson = "";
#endif
removeFile("store.json");
configStoreJson = "";
}