mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-28 15:12:19 +03:00
Save date to flash added
This commit is contained in:
@@ -160,7 +160,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "button",
|
"type": "button",
|
||||||
"title": "Очистить графики и сбросить введенные данные",
|
"title": "Очистить графики и введенные данные",
|
||||||
"action": "/set?cleanlog",
|
"action": "/set?cleanlog",
|
||||||
"class": "btn btn-block btn-default"
|
"class": "btn btn-block btn-default"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ extern boolean telegramInitBeen;
|
|||||||
// Json
|
// Json
|
||||||
extern String configSetupJson; //все настройки
|
extern String configSetupJson; //все настройки
|
||||||
extern String configLiveJson; //все данные с датчиков (связан с mqtt)
|
extern String configLiveJson; //все данные с датчиков (связан с mqtt)
|
||||||
|
extern String configStoreJson; //все данные которые должны сохраняться
|
||||||
extern String configOptionJson; //для трансфера
|
extern String configOptionJson; //для трансфера
|
||||||
|
|
||||||
// Mqtt
|
// Mqtt
|
||||||
|
|||||||
@@ -18,4 +18,4 @@ String jsonWriteBool(String& json, String name, boolean value);
|
|||||||
|
|
||||||
void saveConfig();
|
void saveConfig();
|
||||||
|
|
||||||
void saveLive();
|
void saveStore();
|
||||||
@@ -23,6 +23,7 @@ boolean telegramInitBeen = false;
|
|||||||
// Json
|
// Json
|
||||||
String configSetupJson = "{}";
|
String configSetupJson = "{}";
|
||||||
String configLiveJson = "{}";
|
String configLiveJson = "{}";
|
||||||
|
String configStoreJson = "{}";
|
||||||
String configOptionJson = "{}";
|
String configOptionJson = "{}";
|
||||||
|
|
||||||
// Mqtt
|
// Mqtt
|
||||||
|
|||||||
@@ -12,10 +12,8 @@ void loadConfig() {
|
|||||||
configSetupJson = readFile("config.json", 4096);
|
configSetupJson = readFile("config.json", 4096);
|
||||||
configSetupJson.replace("\r\n", "");
|
configSetupJson.replace("\r\n", "");
|
||||||
|
|
||||||
#ifdef SAVE_SETTINGS_TO_FLASH
|
configStoreJson = readFile("store.json", 4096);
|
||||||
configLiveJson = readFile("live.json", 4096);
|
configStoreJson.replace("\r\n", "");
|
||||||
configLiveJson.replace("\r\n", "");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
jsonWriteStr(configSetupJson, "chipID", chipId);
|
jsonWriteStr(configSetupJson, "chipID", chipId);
|
||||||
jsonWriteInt(configSetupJson, "firmware_version", FIRMWARE_VERSION);
|
jsonWriteInt(configSetupJson, "firmware_version", FIRMWARE_VERSION);
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ void publishWidgets() {
|
|||||||
|
|
||||||
void publishState() {
|
void publishState() {
|
||||||
// берет строку json и ключи превращает в топики а значения колючей в них посылает
|
// берет строку json и ключи превращает в топики а значения колючей в них посылает
|
||||||
String str = configLiveJson;
|
String str = configLiveJson + "," + configStoreJson;
|
||||||
str.replace("{", "");
|
str.replace("{", "");
|
||||||
str.replace("}", "");
|
str.replace("}", "");
|
||||||
str += ",";
|
str += ",";
|
||||||
|
|||||||
@@ -55,8 +55,6 @@ void saveConfig() {
|
|||||||
writeFile(String("config.json"), configSetupJson);
|
writeFile(String("config.json"), configSetupJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveLive() {
|
void saveStore() {
|
||||||
#ifdef SAVE_SETTINGS_TO_FLASH
|
writeFile(String("store.json"), configStoreJson);
|
||||||
writeFile(String("live.json"), configLiveJson);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
@@ -36,6 +36,7 @@ void web_init() {
|
|||||||
|
|
||||||
if (request->hasArg("delAllItems")) {
|
if (request->hasArg("delAllItems")) {
|
||||||
delAllItems();
|
delAllItems();
|
||||||
|
cleanLogAndData();
|
||||||
request->redirect("/?set.device");
|
request->redirect("/?set.device");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,10 @@ void init() {
|
|||||||
request->send(200, "application/json", configLiveJson);
|
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) {
|
server.on("/config.option.json", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
request->send(200, "application/json", configOptionJson);
|
request->send(200, "application/json", configOptionJson);
|
||||||
|
|||||||
@@ -5,13 +5,13 @@
|
|||||||
#include "Class/LineParsing.h"
|
#include "Class/LineParsing.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "BufferExecute.h"
|
#include "BufferExecute.h"
|
||||||
|
//this class save date to flash
|
||||||
ButtonOut::ButtonOut(unsigned int pin, boolean inv, String key) {
|
ButtonOut::ButtonOut(unsigned int pin, boolean inv, String key) {
|
||||||
_pin = pin;
|
_pin = pin;
|
||||||
_inv = inv;
|
_inv = inv;
|
||||||
_key = key;
|
_key = key;
|
||||||
pinMode(_pin, OUTPUT);
|
pinMode(_pin, OUTPUT);
|
||||||
int state = jsonReadInt(configLiveJson, key);
|
int state = jsonReadInt(configStoreJson, key);
|
||||||
this->execute(String(state));
|
this->execute(String(state));
|
||||||
}
|
}
|
||||||
ButtonOut::~ButtonOut() {}
|
ButtonOut::~ButtonOut() {}
|
||||||
@@ -30,8 +30,8 @@ void ButtonOut::execute(String state) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
eventGen2(_key, state);
|
eventGen2(_key, state);
|
||||||
jsonWriteInt(configLiveJson, _key, state.toInt());
|
jsonWriteInt(configStoreJson, _key, state.toInt());
|
||||||
saveLive();
|
saveStore();
|
||||||
publishStatus(_key, state);
|
publishStatus(_key, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
#include "Class/LineParsing.h"
|
#include "Class/LineParsing.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "BufferExecute.h"
|
#include "BufferExecute.h"
|
||||||
|
//this class save date to flash
|
||||||
Input::Input(String key, String widget) {
|
Input::Input(String key, String widget) {
|
||||||
_key = key;
|
_key = key;
|
||||||
String value = jsonReadStr(configLiveJson, key);
|
String value = jsonReadStr(configStoreJson, key);
|
||||||
|
|
||||||
if (value == "") {
|
if (value == "") {
|
||||||
if (widget.indexOf("Digit") != -1) {
|
if (widget.indexOf("Digit") != -1) {
|
||||||
@@ -25,8 +25,8 @@ Input::~Input() {}
|
|||||||
|
|
||||||
void Input::execute(String value) {
|
void Input::execute(String value) {
|
||||||
eventGen2(_key, value);
|
eventGen2(_key, value);
|
||||||
jsonWriteStr(configLiveJson, _key, value);
|
jsonWriteStr(configStoreJson, _key, value);
|
||||||
saveLive();
|
saveStore();
|
||||||
publishStatus(_key, value);
|
publishStatus(_key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ void cleanLogAndData() {
|
|||||||
SerialPrint("I", "System", fname);
|
SerialPrint("I", "System", fname);
|
||||||
removeFile("logs/" + fname);
|
removeFile("logs/" + fname);
|
||||||
}
|
}
|
||||||
removeFile("live.json");
|
|
||||||
configLiveJson = "";
|
|
||||||
#endif
|
#endif
|
||||||
|
removeFile("store.json");
|
||||||
|
configStoreJson = "";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user