Исправил косяк со слетающим config json

This commit is contained in:
Dmitry Borisenko
2021-12-07 05:58:06 +01:00
parent 35923eca7d
commit f28bafa277
9 changed files with 63 additions and 62 deletions

View File

@@ -3,20 +3,20 @@
"chipID": "", "chipID": "",
"apssid": "IoTmanager", "apssid": "IoTmanager",
"appass": "", "appass": "",
"routerssid": "XChangeWIFI", "routerssid": "rise",
"routerpass": "XCh@WIFI", "routerpass": "hostel3333",
"timezone": 1, "timezone": 1,
"ntp": "pool.ntp.org", "ntp": "pool.ntp.org",
"mqttServer": "91.204.228.124", "mqttServer": "M2.WQTT.RU",
"mqttPort": 1883, "mqttPort": 8021,
"mqttPrefix": "/iotTest3", "mqttPrefix": "/iotTest3",
"mqttUser": "rise", "mqttUser": "rise",
"mqttPass": "23ri22se32", "mqttPass": "hostel3333",
"mqttServer2": "M2.WQTT.RU", "mqttServer2": "",
"mqttPort2": 8021, "mqttPort2": 0,
"mqttPrefix2": "/iotTest3", "mqttPrefix2": "",
"mqttUser2": "rise", "mqttUser2": "",
"mqttPass2": "hostel3333", "mqttPass2": "",
"scen": "1", "scen": "1",
"telegramApi": "1416711569:AAEI0j83GmXqwzb_gnK1B0Am0gDwZoJt5xo", "telegramApi": "1416711569:AAEI0j83GmXqwzb_gnK1B0Am0gDwZoJt5xo",
"telegonof": "0", "telegonof": "0",

Binary file not shown.

View File

@@ -3,12 +3,12 @@
"chipID": "", "chipID": "",
"apssid": "IoTmanager", "apssid": "IoTmanager",
"appass": "", "appass": "",
"routerssid": "rise2", "routerssid": "rise",
"routerpass": "hostel3333", "routerpass": "hostel3333",
"timezone": 1, "timezone": 1,
"ntp": "pool.ntp.org", "ntp": "pool.ntp.org",
"mqttServer": "M2.WQTT.RU", "mqttServer": "M2.WQTT.RU",
"mqttPort": 1883, "mqttPort": 8021,
"mqttPrefix": "/iotTest3", "mqttPrefix": "/iotTest3",
"mqttUser": "rise", "mqttUser": "rise",
"mqttPass": "hostel3333", "mqttPass": "hostel3333",
@@ -26,7 +26,7 @@
"webpass": "admin", "webpass": "admin",
"MqttIn": "0", "MqttIn": "0",
"MqttOut": "0", "MqttOut": "0",
"blink": "0", "blink": "1",
"oneWirePin": "2", "oneWirePin": "2",
"serverip": "http://206.189.49.244", "serverip": "http://206.189.49.244",
"uart": "0", "uart": "0",

View File

@@ -13,13 +13,13 @@
#include "items/vPwmOut.h" #include "items/vPwmOut.h"
#include "items/vSensorAnalog.h" #include "items/vSensorAnalog.h"
#include "items/vSensorBme280.h" #include "items/vSensorBme280.h"
#include "items/vSensorSht20.h"
#include "items/vSensorBmp280.h" #include "items/vSensorBmp280.h"
#include "items/vSensorCcs811.h" #include "items/vSensorCcs811.h"
#include "items/vSensorDallas.h" #include "items/vSensorDallas.h"
#include "items/vSensorDht.h" #include "items/vSensorDht.h"
#include "items/vSensorNode.h" #include "items/vSensorNode.h"
#include "items/vSensorPzem.h" #include "items/vSensorPzem.h"
#include "items/vSensorSht20.h"
#include "items/vSensorUltrasonic.h" #include "items/vSensorUltrasonic.h"
#include "items/vSensorUptime.h" #include "items/vSensorUptime.h"
@@ -70,14 +70,14 @@ void deviceInit() {
int errors = myLineParsing.getPinErrors(); int errors = myLineParsing.getPinErrors();
if (errors > 0) { if (errors > 0) {
jsonWriteStr(configSetupJson, F("warning3"), F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #ffc7c7; padding: 10px;'>Обнаружен неверный номер пина</p></font></div>")); jsonWriteStr(configSetupJson, F("warning3"), F("Обнаружен неверный номер пина"));
} else { } else {
jsonWriteStr(configSetupJson, F("warning3"), ""); jsonWriteStr(configSetupJson, F("warning3"), "");
} }
savedFromWeb = false; savedFromWeb = false;
//publishWidgets(); // publishWidgets();
//publishState(); // publishState();
} }
void loadScenario() { void loadScenario() {

View File

@@ -154,8 +154,8 @@ boolean mqttConnect() {
if (connected) { if (connected) {
SerialPrint("I", F("MQTT"), F("✔ connected")); SerialPrint("I", F("MQTT"), F("✔ connected"));
if (currentBroker == 1) jsonWriteStr(configSetupJson, F("warning4"), F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #8ef584; padding: 10px;'>Подключено к основному брокеру</p></font></div>")); if (currentBroker == 1) jsonWriteStr(configSetupJson, F("warning4"), F("Подключено к основному брокеру"));
if (currentBroker == 2) jsonWriteStr(configSetupJson, F("warning4"), F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #8ef584; padding: 10px;'>Подключено к резервному брокеру</p></font></div>")); if (currentBroker == 2) jsonWriteStr(configSetupJson, F("warning4"), F("Подключено к резервному брокеру"));
setLedStatus(LED_OFF); setLedStatus(LED_OFF);
mqttSubscribe(); mqttSubscribe();
res = true; res = true;
@@ -163,7 +163,7 @@ boolean mqttConnect() {
mqttConnectAttempts++; mqttConnectAttempts++;
SerialPrint("E", F("MQTT"), "🡆 Attempt No: " + String(mqttConnectAttempts) + " could't connect, retry in " + String(MQTT_RECONNECT_INTERVAL / 1000) + "s"); SerialPrint("E", F("MQTT"), "🡆 Attempt No: " + String(mqttConnectAttempts) + " could't connect, retry in " + String(MQTT_RECONNECT_INTERVAL / 1000) + "s");
setLedStatus(LED_FAST); setLedStatus(LED_FAST);
jsonWriteStr(configSetupJson, F("warning4"), F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #fa987a; padding: 10px;'>Не подключено брокеру</p></font></div>")); jsonWriteStr(configSetupJson, F("warning4"), F("Не подключено брокеру"));
if (mqttConnectAttempts >= CHANGE_BROKER_AFTER) { if (mqttConnectAttempts >= CHANGE_BROKER_AFTER) {
mqttConnectAttempts = 0; mqttConnectAttempts = 0;
if (isSecondBrokerSet()) { if (isSecondBrokerSet()) {
@@ -180,14 +180,14 @@ boolean mqttConnect() {
void mqttCallback(char* topic, uint8_t* payload, size_t length) { void mqttCallback(char* topic, uint8_t* payload, size_t length) {
String topicStr = String(topic); String topicStr = String(topic);
//SerialPrint("I", "=>MQTT", topicStr); // SerialPrint("I", "=>MQTT", topicStr);
String payloadStr; String payloadStr;
payloadStr.reserve(length + 1); payloadStr.reserve(length + 1);
for (size_t i = 0; i < length; i++) { for (size_t i = 0; i < length; i++) {
payloadStr += (char)payload[i]; payloadStr += (char)payload[i];
} }
//SerialPrint("I", "=>MQTT", payloadStr); // SerialPrint("I", "=>MQTT", payloadStr);
if (payloadStr.startsWith("HELLO")) { if (payloadStr.startsWith("HELLO")) {
SerialPrint("I", F("MQTT"), F("Full update")); SerialPrint("I", F("MQTT"), F("Full update"));
@@ -321,8 +321,8 @@ void publishWidgets() {
line = all_widgets.substring(psn_1, psn_2); line = all_widgets.substring(psn_1, psn_2);
line.replace("\n", ""); line.replace("\n", "");
line.replace("\r\n", ""); line.replace("\r\n", "");
//jsonWriteStr(line, "id", String(counter)); // jsonWriteStr(line, "id", String(counter));
//jsonWriteStr(line, "pageId", String(counter)); // jsonWriteStr(line, "pageId", String(counter));
counter++; counter++;
sendMQTT("config", line); sendMQTT("config", line);
Serial.println("[V] " + line); Serial.println("[V] " + line);

View File

@@ -27,7 +27,7 @@ void upgradeInit() {
if (lastVersion > 0) { if (lastVersion > 0) {
SerialPrint("I", F("Update"), "available version: " + String(lastVersion)); SerialPrint("I", F("Update"), "available version: " + String(lastVersion));
if (lastVersion > FIRMWARE_VERSION) { if (lastVersion > FIRMWARE_VERSION) {
jsonWriteStr(configSetupJson, "warning2", F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #ffc7c7; padding: 10px;'>Вышла новая версия прошивки, нажмите <b>обновить прошивку</b></p></font></div>")); jsonWriteStr(configSetupJson, "warning2", F("Вышла новая версия прошивки, нажмите обновить прошивку"));
} }
} }
}; };
@@ -69,11 +69,11 @@ void upgrade_firmware(int type) {
devconfig_ForUpdate = readFile(String(DEVICE_CONFIG_FILE), 4096); devconfig_ForUpdate = readFile(String(DEVICE_CONFIG_FILE), 4096);
configSetup_ForUpdate = configSetupJson; configSetup_ForUpdate = configSetupJson;
if (type == 1) { //only build if (type == 1) { // only build
if (upgradeBuild()) restartEsp(); if (upgradeBuild()) restartEsp();
} }
else if (type == 2) { //only spiffs else if (type == 2) { // only spiffs
if (upgradeFS()) { if (upgradeFS()) {
writeFile(String(DEVICE_SCENARIO_FILE), scenario_ForUpdate); writeFile(String(DEVICE_SCENARIO_FILE), scenario_ForUpdate);
writeFile(String(DEVICE_CONFIG_FILE), devconfig_ForUpdate); writeFile(String(DEVICE_CONFIG_FILE), devconfig_ForUpdate);
@@ -82,7 +82,7 @@ void upgrade_firmware(int type) {
} }
} }
else if (type == 3) { //spiffs and build else if (type == 3) { // spiffs and build
if (upgradeFS()) { if (upgradeFS()) {
writeFile(String(DEVICE_SCENARIO_FILE), scenario_ForUpdate); writeFile(String(DEVICE_SCENARIO_FILE), scenario_ForUpdate);
writeFile(String(DEVICE_CONFIG_FILE), devconfig_ForUpdate); writeFile(String(DEVICE_CONFIG_FILE), devconfig_ForUpdate);

View File

@@ -1,4 +1,5 @@
#include "Utils/WiFiUtils.h" #include "Utils/WiFiUtils.h"
#include "FileSystem.h" #include "FileSystem.h"
void routerConnect() { void routerConnect() {
@@ -63,7 +64,7 @@ bool startAPMode() {
SerialPrint("I", "WIFI", "AP IP: " + myIP.toString()); SerialPrint("I", "WIFI", "AP IP: " + myIP.toString());
jsonWriteStr(configSetupJson, "ip", myIP.toString()); jsonWriteStr(configSetupJson, "ip", myIP.toString());
//if (jsonReadInt(configOptionJson, "pass_status") != 1) { // if (jsonReadInt(configOptionJson, "pass_status") != 1) {
ts.add( ts.add(
WIFI_SCAN, 10 * 1000, [&](void*) { WIFI_SCAN, 10 * 1000, [&](void*) {
String sta_ssid = jsonReadStr(configSetupJson, "routerssid"); String sta_ssid = jsonReadStr(configSetupJson, "routerssid");
@@ -88,7 +89,7 @@ boolean RouterFind(String ssid) {
if (n == -2) { //Сканирование не было запущено, запускаем if (n == -2) { //Сканирование не было запущено, запускаем
SerialPrint("I", "WIFI", "start scanning"); SerialPrint("I", "WIFI", "start scanning");
WiFi.scanNetworks(true, false); //async, show_hidden WiFi.scanNetworks(true, false); // async, show_hidden
} }
else if (n == -1) { //Сканирование все еще выполняется else if (n == -1) { //Сканирование все еще выполняется
@@ -146,25 +147,25 @@ void wifiSignalInit() {
switch (RSSIquality()) { switch (RSSIquality()) {
case 0: case 0:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>не подключено к роутеру</font>")); jsonWriteStr(configSetupJson, F("signal"), F("не подключено к роутеру"));
break; break;
case 1: case 1:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>нет сигнала</font>")); jsonWriteStr(configSetupJson, F("signal"), F("нет сигнала"));
break; break;
case 2: case 2:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>очень низкий</font>")); jsonWriteStr(configSetupJson, F("signal"), F("очень низкий"));
break; break;
case 3: case 3:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='orange'>низкий</font>")); jsonWriteStr(configSetupJson, F("signal"), F("низкий"));
break; break;
case 4: case 4:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>хороший</font>")); jsonWriteStr(configSetupJson, F("signal"), F("хороший"));
break; break;
case 5: case 5:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>очень хороший</font>")); jsonWriteStr(configSetupJson, F("signal"), F("очень хороший"));
break; break;
case 6: case 6:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>отличный</font>")); jsonWriteStr(configSetupJson, F("signal"), F("отличный"));
break; break;
} }
}, },

View File

@@ -1,4 +1,5 @@
#include "Web.h" #include "Web.h"
#include "BufferExecute.h" #include "BufferExecute.h"
#include "Class/NotAsync.h" #include "Class/NotAsync.h"
#include "Global.h" #include "Global.h"
@@ -28,13 +29,13 @@ void web_init() {
if (request->hasArg(F("addPreset"))) { if (request->hasArg(F("addPreset"))) {
addPreset2(request->getParam(F("addPreset"))->value().toInt()); addPreset2(request->getParam(F("addPreset"))->value().toInt());
jsonWriteStr(configSetupJson, F("warning1"), F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #ffc7c7; padding: 10px;'>Требуется перезагрузка</p></font></div>")); jsonWriteStr(configSetupJson, F("warning1"), F("Требуется перезагрузка"));
request->redirect(F("/?set.device")); request->redirect(F("/?set.device"));
} }
if (request->hasArg(F("delChoosingItems"))) { if (request->hasArg(F("delChoosingItems"))) {
jsonWriteStr(configSetupJson, F("warning1"), F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #ffc7c7; padding: 10px;'>Требуется перезагрузка</p></font></div>")); jsonWriteStr(configSetupJson, F("warning1"), F("Требуется перезагрузка"));
myNotAsyncActions->make(do_delChoosingItems); myNotAsyncActions->make(do_delChoosingItems);
request->send(200); request->send(200);
} }
@@ -44,7 +45,7 @@ void web_init() {
#ifdef EnableLogging #ifdef EnableLogging
cleanLogAndData(); cleanLogAndData();
#endif #endif
jsonWriteStr(configSetupJson, F("warning1"), F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #ffc7c7; padding: 10px;'>Требуется перезагрузка</p></font></div>")); jsonWriteStr(configSetupJson, F("warning1"), F("Требуется перезагрузка"));
request->redirect(F("/?set.device")); request->redirect(F("/?set.device"));
} }
@@ -174,7 +175,7 @@ void web_init() {
} }
//==============================mqtt settings============================================= //==============================mqtt settings=============================================
//primary // primary
if (request->hasArg(F("mqttServer"))) { if (request->hasArg(F("mqttServer"))) {
jsonWriteStr(configSetupJson, F("mqttServer"), request->getParam(F("mqttServer"))->value()); jsonWriteStr(configSetupJson, F("mqttServer"), request->getParam(F("mqttServer"))->value());
saveConfig(); saveConfig();
@@ -206,7 +207,7 @@ void web_init() {
myNotAsyncActions->make(do_MQTTPARAMSCHANGED); myNotAsyncActions->make(do_MQTTPARAMSCHANGED);
request->send(200); request->send(200);
} }
//secondary // secondary
if (request->hasArg(F("mqttServer2"))) { if (request->hasArg(F("mqttServer2"))) {
jsonWriteStr(configSetupJson, F("mqttServer2"), request->getParam(F("mqttServer2"))->value()); jsonWriteStr(configSetupJson, F("mqttServer2"), request->getParam(F("mqttServer2"))->value());
saveConfig(); saveConfig();
@@ -240,7 +241,7 @@ void web_init() {
} }
if (request->hasArg("mqttsend")) { if (request->hasArg("mqttsend")) {
//myNotAsyncActions->make(do_MQTTUDP); // myNotAsyncActions->make(do_MQTTUDP);
request->send(200); request->send(200);
} }
@@ -336,7 +337,7 @@ void web_init() {
serverIP = jsonReadStr(configSetupJson, "serverip"); serverIP = jsonReadStr(configSetupJson, "serverip");
request->send(200); request->send(200);
} }
//set?order=button_1 // set?order=button_1
if (request->hasArg("order")) { if (request->hasArg("order")) {
String order = request->getParam("order")->value(); String order = request->getParam("order")->value();
order.replace("_", " "); order.replace("_", " ");
@@ -351,7 +352,7 @@ void web_init() {
request->send(200); request->send(200);
} }
//gate mode // gate mode
if (request->hasArg("gateAuto")) { if (request->hasArg("gateAuto")) {
bool value = request->getParam("gateAuto")->value().toInt(); bool value = request->getParam("gateAuto")->value().toInt();
@@ -359,19 +360,18 @@ void web_init() {
saveConfig(); saveConfig();
request->send(200); request->send(200);
} }
}); });
//server.on("/del", HTTP_GET, [](AsyncWebServerRequest* request) { // server.on("/del", HTTP_GET, [](AsyncWebServerRequest* request) {
// if (request->hasArg("file") && request->hasArg("line")) { // if (request->hasArg("file") && request->hasArg("line")) {
// String fileName = request->getParam("file")->value(); // String fileName = request->getParam("file")->value();
// Serial.println(fileName); // Serial.println(fileName);
// int line = request->getParam("line")->value().toInt(); // int line = request->getParam("line")->value().toInt();
// Serial.println(line); // Serial.println(line);
// myNotAsyncActions->make(do_delChoosingItems); // myNotAsyncActions->make(do_delChoosingItems);
// request->redirect(F("/?set.device")); // request->redirect(F("/?set.device"));
// } // }
//}); // });
server.on("/check", HTTP_GET, [](AsyncWebServerRequest* request) { server.on("/check", HTTP_GET, [](AsyncWebServerRequest* request) {
myNotAsyncActions->make(do_GETLASTVERSION); myNotAsyncActions->make(do_GETLASTVERSION);
@@ -402,8 +402,8 @@ void web_init() {
}); });
/* /*
* Upgrade * Upgrade
*/ */
server.on("/upgrade", HTTP_GET, [](AsyncWebServerRequest* request) { server.on("/upgrade", HTTP_GET, [](AsyncWebServerRequest* request) {
myNotAsyncActions->make(do_UPGRADE); myNotAsyncActions->make(do_UPGRADE);
request->send(200, "text/html"); request->send(200, "text/html");

View File

@@ -11,6 +11,7 @@
#include "Global.h" #include "Global.h"
#include "Init.h" #include "Init.h"
#include "ItemsList.h" #include "ItemsList.h"
#include "MySensorsDataParse.h"
#include "RemoteOrdersUdp.h" #include "RemoteOrdersUdp.h"
#include "SoftUART.h" #include "SoftUART.h"
#include "Telegram.h" #include "Telegram.h"
@@ -18,22 +19,21 @@
#include "Utils/StatUtils.h" #include "Utils/StatUtils.h"
#include "Utils/Timings.h" #include "Utils/Timings.h"
#include "Utils/WebUtils.h" #include "Utils/WebUtils.h"
#include "MySensorsDataParse.h"
#include "items/ButtonInClass.h" #include "items/ButtonInClass.h"
#include "items/vCountDown.h" #include "items/vCountDown.h"
#include "items/vImpulsOut.h" #include "items/vImpulsOut.h"
#include "items/vLogging.h" #include "items/vLogging.h"
#include "items/vSensorAnalog.h" #include "items/vSensorAnalog.h"
#include "items/vSensorBme280.h" #include "items/vSensorBme280.h"
#include "items/vSensorSht20.h"
#include "items/vSensorBmp280.h" #include "items/vSensorBmp280.h"
#include "items/vSensorCcs811.h" #include "items/vSensorCcs811.h"
#include "items/vSensorDallas.h" #include "items/vSensorDallas.h"
#include "items/vSensorDht.h" #include "items/vSensorDht.h"
#include "items/vSensorNode.h"
#include "items/vSensorPzem.h" #include "items/vSensorPzem.h"
#include "items/vSensorSht20.h"
#include "items/vSensorUltrasonic.h" #include "items/vSensorUltrasonic.h"
#include "items/vSensorUptime.h" #include "items/vSensorUptime.h"
#include "items/vSensorNode.h"
void not_async_actions(); void not_async_actions();
@@ -80,7 +80,7 @@ void setup() {
getFSInfo(); getFSInfo();
//testsPerform(); // testsPerform();
just_load = false; just_load = false;
initialized = true; initialized = true;