407 добавил лог в веб интерфейс!

This commit is contained in:
Dmitry Borisenko
2022-02-19 23:42:24 +01:00
parent 27dfc24d4c
commit cce5726390
7 changed files with 38 additions and 12 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -14,5 +14,6 @@
"mqttPrefix": "/ver4test", "mqttPrefix": "/ver4test",
"mqttUser": "rise", "mqttUser": "rise",
"mqttPass": "hostel3333", "mqttPass": "hostel3333",
"serverip": "http://206.189.49.244:8081" "serverip": "http://206.189.49.244:8081",
"log": 0
} }

View File

@@ -1,7 +1,7 @@
#pragma once #pragma once
//Версия прошивки //Версия прошивки
#define FIRMWARE_VERSION 405 #define FIRMWARE_VERSION 407
#ifdef esp8266_4mb #ifdef esp8266_4mb
#define FIRMWARE_NAME "esp8266_4mb" #define FIRMWARE_NAME "esp8266_4mb"
@@ -51,3 +51,14 @@ enum NotAsyncActions {
do_MQTTPARAMSCHANGED, do_MQTTPARAMSCHANGED,
do_LAST, do_LAST,
}; };
//состояния обновления
enum UpdateStates { NOT_STARTED,
UPDATE_FS_IN_PROGRESS,
UPDATE_FS_COMPLETED,
UPDATE_FS_FAILED,
UPDATE_BUILD_IN_PROGRESS,
UPDATE_BUILD_COMPLETED,
UPDATE_BUILD_FAILED,
PATH_ERROR
};

View File

@@ -23,3 +23,4 @@ extern void restartEsp();
extern const String getBinPath(String file); extern const String getBinPath(String file);
extern void putUserDataToRam(); extern void putUserDataToRam();
extern void saveUserDataToFlash(); extern void saveUserDataToFlash();
extern void handleUpdateStatus(bool send, int state);

View File

@@ -36,8 +36,10 @@ bool upgradeFS() {
bool ret = false; bool ret = false;
WiFiClient wifiClient; WiFiClient wifiClient;
SerialPrint("!!!", F("Update"), F("Start upgrade FS...")); SerialPrint("!!!", F("Update"), F("Start upgrade FS..."));
handleUpdateStatus(true, UPDATE_FS_IN_PROGRESS);
if (getBinPath("") == "error") { if (getBinPath("") == "error") {
SerialPrint("E", F("Update"), F("FS Path error")); SerialPrint("E", F("Update"), F("FS Path error"));
handleUpdateStatus(true, PATH_ERROR);
return ret; return ret;
} }
#ifdef ESP8266 #ifdef ESP8266
@@ -52,9 +54,10 @@ bool upgradeFS() {
//если FS обновилась успешно //если FS обновилась успешно
if (retFS == HTTP_UPDATE_OK) { if (retFS == HTTP_UPDATE_OK) {
SerialPrint("!!!", F("Update"), F("FS upgrade done!")); SerialPrint("!!!", F("Update"), F("FS upgrade done!"));
handleUpdateStatus(true, UPDATE_FS_COMPLETED);
ret = true; ret = true;
} }
handleUpdateStatus(true, UPDATE_FS_FAILED);
return ret; return ret;
} }
@@ -62,8 +65,10 @@ bool upgradeBuild() {
bool ret = false; bool ret = false;
WiFiClient wifiClient; WiFiClient wifiClient;
SerialPrint("!!!", F("Update"), F("Start upgrade BUILD...")); SerialPrint("!!!", F("Update"), F("Start upgrade BUILD..."));
handleUpdateStatus(true, UPDATE_BUILD_IN_PROGRESS);
if (getBinPath("") == "error") { if (getBinPath("") == "error") {
SerialPrint("E", F("Update"), F("Build Path error")); SerialPrint("E", F("Update"), F("Build Path error"));
handleUpdateStatus(true, PATH_ERROR);
return ret; return ret;
} }
#ifdef esp8266_4mb #ifdef esp8266_4mb
@@ -78,9 +83,10 @@ bool upgradeBuild() {
//если BUILD обновился успешно //если BUILD обновился успешно
if (retBuild == HTTP_UPDATE_OK) { if (retBuild == HTTP_UPDATE_OK) {
SerialPrint("!!!", F("Update"), F("BUILD upgrade done!")); SerialPrint("!!!", F("Update"), F("BUILD upgrade done!"));
handleUpdateStatus(true, UPDATE_BUILD_COMPLETED);
ret = true; ret = true;
} }
handleUpdateStatus(true, UPDATE_BUILD_FAILED);
return ret; return ret;
} }
@@ -118,3 +124,8 @@ void saveUserDataToFlash() {
writeFile("/settings.json", update.settingsFlashJson); writeFile("/settings.json", update.settingsFlashJson);
writeFile("/layout.json", update.layoutJson); writeFile("/layout.json", update.layoutJson);
} }
void handleUpdateStatus(bool send, int state) {
jsonWriteInt_(errorsHeapJson, F("upd"), state);
if (!send) standWebSocket.broadcastTXT(errorsHeapJson);
}

View File

@@ -2,8 +2,10 @@
#include "utils/SerialPrint.h" #include "utils/SerialPrint.h"
void SerialPrint(String errorLevel, String module, String msg) { void SerialPrint(String errorLevel, String module, String msg) {
Serial.println(prettyMillis(millis()) + " [" + errorLevel + "] [" + module + "] " + msg); String tosend = prettyMillis(millis()) + " [" + errorLevel + "] [" + module + "] " + msg;
String tosend = "[" + errorLevel + "] [" + module + "] " + msg; Serial.println(tosend);
// ws.textAll(tosend); if (jsonReadInt(settingsFlashJson, F("log")) != 0) {
standWebSocket.broadcastTXT("/log|" + tosend);
}
} }