Исправил косяк со слетающим 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": "",
"apssid": "IoTmanager",
"appass": "",
"routerssid": "XChangeWIFI",
"routerpass": "XCh@WIFI",
"routerssid": "rise",
"routerpass": "hostel3333",
"timezone": 1,
"ntp": "pool.ntp.org",
"mqttServer": "91.204.228.124",
"mqttPort": 1883,
"mqttServer": "M2.WQTT.RU",
"mqttPort": 8021,
"mqttPrefix": "/iotTest3",
"mqttUser": "rise",
"mqttPass": "23ri22se32",
"mqttServer2": "M2.WQTT.RU",
"mqttPort2": 8021,
"mqttPrefix2": "/iotTest3",
"mqttUser2": "rise",
"mqttPass2": "hostel3333",
"mqttPass": "hostel3333",
"mqttServer2": "",
"mqttPort2": 0,
"mqttPrefix2": "",
"mqttUser2": "",
"mqttPass2": "",
"scen": "1",
"telegramApi": "1416711569:AAEI0j83GmXqwzb_gnK1B0Am0gDwZoJt5xo",
"telegonof": "0",

Binary file not shown.

View File

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

View File

@@ -13,13 +13,13 @@
#include "items/vPwmOut.h"
#include "items/vSensorAnalog.h"
#include "items/vSensorBme280.h"
#include "items/vSensorSht20.h"
#include "items/vSensorBmp280.h"
#include "items/vSensorCcs811.h"
#include "items/vSensorDallas.h"
#include "items/vSensorDht.h"
#include "items/vSensorNode.h"
#include "items/vSensorPzem.h"
#include "items/vSensorSht20.h"
#include "items/vSensorUltrasonic.h"
#include "items/vSensorUptime.h"
@@ -70,14 +70,14 @@ void deviceInit() {
int errors = myLineParsing.getPinErrors();
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 {
jsonWriteStr(configSetupJson, F("warning3"), "");
}
savedFromWeb = false;
//publishWidgets();
//publishState();
// publishWidgets();
// publishState();
}
void loadScenario() {

View File

@@ -154,8 +154,8 @@ boolean mqttConnect() {
if (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 == 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 == 1) jsonWriteStr(configSetupJson, F("warning4"), F("Подключено к основному брокеру"));
if (currentBroker == 2) jsonWriteStr(configSetupJson, F("warning4"), F("Подключено к резервному брокеру"));
setLedStatus(LED_OFF);
mqttSubscribe();
res = true;
@@ -163,7 +163,7 @@ boolean mqttConnect() {
mqttConnectAttempts++;
SerialPrint("E", F("MQTT"), "🡆 Attempt No: " + String(mqttConnectAttempts) + " could't connect, retry in " + String(MQTT_RECONNECT_INTERVAL / 1000) + "s");
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) {
mqttConnectAttempts = 0;
if (isSecondBrokerSet()) {
@@ -180,14 +180,14 @@ boolean mqttConnect() {
void mqttCallback(char* topic, uint8_t* payload, size_t length) {
String topicStr = String(topic);
//SerialPrint("I", "=>MQTT", topicStr);
// SerialPrint("I", "=>MQTT", topicStr);
String payloadStr;
payloadStr.reserve(length + 1);
for (size_t i = 0; i < length; i++) {
payloadStr += (char)payload[i];
}
//SerialPrint("I", "=>MQTT", payloadStr);
// SerialPrint("I", "=>MQTT", payloadStr);
if (payloadStr.startsWith("HELLO")) {
SerialPrint("I", F("MQTT"), F("Full update"));
@@ -321,8 +321,8 @@ void publishWidgets() {
line = all_widgets.substring(psn_1, psn_2);
line.replace("\n", "");
line.replace("\r\n", "");
//jsonWriteStr(line, "id", String(counter));
//jsonWriteStr(line, "pageId", String(counter));
// jsonWriteStr(line, "id", String(counter));
// jsonWriteStr(line, "pageId", String(counter));
counter++;
sendMQTT("config", line);
Serial.println("[V] " + line);

View File

@@ -27,7 +27,7 @@ void upgradeInit() {
if (lastVersion > 0) {
SerialPrint("I", F("Update"), "available version: " + String(lastVersion));
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);
configSetup_ForUpdate = configSetupJson;
if (type == 1) { //only build
if (type == 1) { // only build
if (upgradeBuild()) restartEsp();
}
else if (type == 2) { //only spiffs
else if (type == 2) { // only spiffs
if (upgradeFS()) {
writeFile(String(DEVICE_SCENARIO_FILE), scenario_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()) {
writeFile(String(DEVICE_SCENARIO_FILE), scenario_ForUpdate);
writeFile(String(DEVICE_CONFIG_FILE), devconfig_ForUpdate);

View File

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

View File

@@ -1,4 +1,5 @@
#include "Web.h"
#include "BufferExecute.h"
#include "Class/NotAsync.h"
#include "Global.h"
@@ -28,13 +29,13 @@ void web_init() {
if (request->hasArg(F("addPreset"))) {
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"));
}
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);
request->send(200);
}
@@ -44,7 +45,7 @@ void web_init() {
#ifdef EnableLogging
cleanLogAndData();
#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"));
}
@@ -174,7 +175,7 @@ void web_init() {
}
//==============================mqtt settings=============================================
//primary
// primary
if (request->hasArg(F("mqttServer"))) {
jsonWriteStr(configSetupJson, F("mqttServer"), request->getParam(F("mqttServer"))->value());
saveConfig();
@@ -206,7 +207,7 @@ void web_init() {
myNotAsyncActions->make(do_MQTTPARAMSCHANGED);
request->send(200);
}
//secondary
// secondary
if (request->hasArg(F("mqttServer2"))) {
jsonWriteStr(configSetupJson, F("mqttServer2"), request->getParam(F("mqttServer2"))->value());
saveConfig();
@@ -240,7 +241,7 @@ void web_init() {
}
if (request->hasArg("mqttsend")) {
//myNotAsyncActions->make(do_MQTTUDP);
// myNotAsyncActions->make(do_MQTTUDP);
request->send(200);
}
@@ -336,7 +337,7 @@ void web_init() {
serverIP = jsonReadStr(configSetupJson, "serverip");
request->send(200);
}
//set?order=button_1
// set?order=button_1
if (request->hasArg("order")) {
String order = request->getParam("order")->value();
order.replace("_", " ");
@@ -351,7 +352,7 @@ void web_init() {
request->send(200);
}
//gate mode
// gate mode
if (request->hasArg("gateAuto")) {
bool value = request->getParam("gateAuto")->value().toInt();
@@ -359,19 +360,18 @@ void web_init() {
saveConfig();
request->send(200);
}
});
//server.on("/del", HTTP_GET, [](AsyncWebServerRequest* request) {
// if (request->hasArg("file") && request->hasArg("line")) {
// String fileName = request->getParam("file")->value();
// Serial.println(fileName);
// int line = request->getParam("line")->value().toInt();
// Serial.println(line);
// myNotAsyncActions->make(do_delChoosingItems);
// request->redirect(F("/?set.device"));
// }
//});
// server.on("/del", HTTP_GET, [](AsyncWebServerRequest* request) {
// if (request->hasArg("file") && request->hasArg("line")) {
// String fileName = request->getParam("file")->value();
// Serial.println(fileName);
// int line = request->getParam("line")->value().toInt();
// Serial.println(line);
// myNotAsyncActions->make(do_delChoosingItems);
// request->redirect(F("/?set.device"));
// }
// });
server.on("/check", HTTP_GET, [](AsyncWebServerRequest* request) {
myNotAsyncActions->make(do_GETLASTVERSION);
@@ -402,8 +402,8 @@ void web_init() {
});
/*
* Upgrade
*/
* Upgrade
*/
server.on("/upgrade", HTTP_GET, [](AsyncWebServerRequest* request) {
myNotAsyncActions->make(do_UPGRADE);
request->send(200, "text/html");

View File

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