версия 454 - исправлены баги, добавлена обратная связь на ota

This commit is contained in:
IoT Manager
2023-10-11 01:46:12 +02:00
parent 876ca9b378
commit 1a574e37cd
15 changed files with 49 additions and 72 deletions

View File

@@ -4,6 +4,8 @@ updateFirm update;
void upgrade_firmware(int type, String path) {
putUserDataToRam();
// сбросим файл статуса последнего обновления
writeFile("ota.json", "{}");
// only build
if (type == 1) {
@@ -36,10 +38,10 @@ bool upgradeFS(String path) {
bool ret = false;
WiFiClient wifiClient;
SerialPrint("!!!", F("Update"), "Start upgrade FS... " + path);
handleUpdateStatus(true, UPDATE_FS_IN_PROGRESS);
if (path == "") {
SerialPrint("E", F("Update"), F("FS Path error"));
handleUpdateStatus(true, PATH_ERROR);
saveUpdeteStatus("fs", PATH_ERROR);
return ret;
}
#ifdef ESP8266
@@ -55,10 +57,10 @@ bool upgradeFS(String path) {
// если FS обновилась успешно
if (retFS == HTTP_UPDATE_OK) {
SerialPrint("!!!", F("Update"), F("FS upgrade done!"));
handleUpdateStatus(true, UPDATE_FS_COMPLETED);
saveUpdeteStatus("fs", UPDATE_COMPLETED);
ret = true;
} else {
handleUpdateStatus(true, UPDATE_FS_FAILED);
saveUpdeteStatus("fs", UPDATE_FAILED);
if (retFS == HTTP_UPDATE_FAILED) {
SerialPrint("E", F("Update"), "HTTP_UPDATE_FAILED");
} else if (retFS == HTTP_UPDATE_NO_UPDATES) {
@@ -72,10 +74,10 @@ bool upgradeBuild(String path) {
bool ret = false;
WiFiClient wifiClient;
SerialPrint("!!!", F("Update"), "Start upgrade BUILD... " + path);
handleUpdateStatus(true, UPDATE_BUILD_IN_PROGRESS);
if (path == "") {
SerialPrint("E", F("Update"), F("Build Path error"));
handleUpdateStatus(true, PATH_ERROR);
saveUpdeteStatus("build", PATH_ERROR);
return ret;
}
#if defined(esp8266_4mb) || defined(esp8266_16mb) || defined(esp8266_1mb) || defined(esp8266_1mb_ota) || defined(esp8266_2mb) || defined(esp8266_2mb_ota)
@@ -90,10 +92,10 @@ bool upgradeBuild(String path) {
// если BUILD обновился успешно
if (retBuild == HTTP_UPDATE_OK) {
SerialPrint("!!!", F("Update"), F("BUILD upgrade done!"));
handleUpdateStatus(true, UPDATE_BUILD_COMPLETED);
saveUpdeteStatus("build", UPDATE_COMPLETED);
ret = true;
} else {
handleUpdateStatus(true, UPDATE_BUILD_FAILED);
saveUpdeteStatus("build", UPDATE_FAILED);
if (retBuild == HTTP_UPDATE_FAILED) {
SerialPrint("E", F("Update"), "HTTP_UPDATE_FAILED");
} else if (retBuild == HTTP_UPDATE_NO_UPDATES) {
@@ -132,7 +134,7 @@ void putUserDataToRam() {
update.settingsFlashJson = readFile("settings.json", 4096);
update.layoutJson = readFile("layout.json", 4096);
update.scenarioTxt = readFile("scenario.txt", 4096);
update.chartsData = createDataBaseSting();
// update.chartsData = createDataBaseSting();
}
void saveUserDataToFlash() {
@@ -140,10 +142,13 @@ void saveUserDataToFlash() {
writeFile("/settings.json", update.settingsFlashJson);
writeFile("/layout.json", update.layoutJson);
writeFile("/scenario.txt", update.scenarioTxt);
writeDataBaseSting(update.chartsData);
// writeDataBaseSting(update.chartsData);
}
void handleUpdateStatus(bool send, int state) {
jsonWriteInt_(errorsHeapJson, F("upd"), state);
if (send) sendStringToWs("errors", errorsHeapJson, -1);
void saveUpdeteStatus(String key, int val) {
const String path = "ota.json";
String json = readFile(path, 1024);
if (json == "failed") json = "{}";
jsonWriteInt_(json, key, val);
writeFile(path, json);
}

View File

@@ -219,6 +219,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
//----------------------------------------------------------------------//
if (headerStr == "/profile|") {
// для версии 451 отдаем myProfile.json
sendFileToWsByFrames("/ota.json", "otaupd", "", num, WEB_SOCKETS_FRAME_SIZE);
if (FileFS.exists("/myProfile.json")) {
sendFileToWsByFrames("/myProfile.json", "prfile", "", num, WEB_SOCKETS_FRAME_SIZE);
// для версии 452 и более отдаем flashProfile.json

View File

@@ -65,14 +65,6 @@
"usedLibs": {
"esp32_4mb": [],
"esp32s2_4mb": [],
"esp32_16mb": [],
"esp8266_4mb": [],
"esp8266_16mb": [],
"esp8266_1mb": [],
"esp8266_1mb_ota": [],
"esp8285_1mb": [],
"esp8285_1mb_ota": [],
"esp8266_2mb": [],
"esp8266_2mb_ota": []
"esp32_16mb": []
}
}

View File

@@ -124,8 +124,8 @@ const String readFile(const String& filename, size_t max_size) {
size_t size = file.size();
if (size > max_size) {
file.close();
if (path == "/config.json")
return "[]";
// что это за бред!
if (path == "/config.json") return "[]";
return "large";
}
String temp = file.readString();
@@ -133,9 +133,7 @@ const String readFile(const String& filename, size_t max_size) {
return temp;
}
const String filepath(const String& filename) {
return filename.startsWith("/") ? filename : "/" + filename;
}
const String filepath(const String& filename) { return filename.startsWith("/") ? filename : "/" + filename; }
bool cutFile(const String& src, const String& dst) {
String srcPath = filepath(src);
@@ -288,9 +286,7 @@ String getFilesList(String& directory) {
}
#if defined(ESP8266)
bool getInfo(FSInfo& info) {
return FileFS.info(info);
}
bool getInfo(FSInfo& info) { return FileFS.info(info); }
// Информация о ФС
IoTFSInfo getFSInfo() {

View File

@@ -2,13 +2,9 @@
#include "utils/FileUtils.h"
// new================================================================================
String jsonReadStrDoc(DynamicJsonDocument &doc, String name) {
return doc[name].as<String>();
}
String jsonReadStrDoc(DynamicJsonDocument &doc, String name) { return doc[name].as<String>(); }
void jsonWriteStrDoc(DynamicJsonDocument &doc, String name, String value) {
doc[name] = value;
}
void jsonWriteStrDoc(DynamicJsonDocument &doc, String name, String value) { doc[name] = value; }
// new==============================================================================
bool jsonRead(const String &json, String key, long &value, bool e) {
@@ -114,21 +110,14 @@ bool jsonReadArray(const String &json, String key, std::vector<String> &jArray,
}
return false;
}
// SerialPrint("E", F("jsonReadArray"), key + " doc " + doc[key].as<String>());
if (doc[key].is<JsonArray>()) {
for (int8_t i = 0; i < doc[key].size(); i++)
jArray.push_back(doc[key][i].as<String>());
// SerialPrint("E", F("jsonReadArray"), "isArray"+key + " doc " + doc[key].as<String>());
for (int8_t i = 0; i < doc[key].size(); i++) jArray.push_back(doc[key][i].as<String>());
} else {
jArray.push_back(doc[key].as<String>());
// DynamicJsonDocument docArr(JSON_BUFFER_SIZE/5);
// jArray = doc[key].as<JsonArray>();
// String tmp = doc[key].as<String>();
// jArray.add("dsdsd");
// SerialPrint("E", F("jsonReadArray"), "notArray"+key + " doc " + doc[key].as<String>());
// SerialPrint("E", F("jsonReadArray"), "count: " + String(jArray.size()) +" key: " + key + " arr " + jArray[0]);
}
// SerialPrint("E", F("jsonReadArray"), "count: " + String(jArray.size()) +" key: " + key + " doc " + jArray[0].as<String>());
return true;
}