mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
глобальное изменение системы обновления прошивки
This commit is contained in:
@@ -2,12 +2,12 @@
|
||||
|
||||
updateFirm update;
|
||||
|
||||
void upgrade_firmware(int type) {
|
||||
void upgrade_firmware(int type, String path) {
|
||||
putUserDataToRam();
|
||||
|
||||
// only build
|
||||
if (type == 1) {
|
||||
if (upgradeBuild()) {
|
||||
if (upgradeBuild(path)) {
|
||||
saveUserDataToFlash();
|
||||
restartEsp();
|
||||
}
|
||||
@@ -15,7 +15,7 @@ void upgrade_firmware(int type) {
|
||||
|
||||
// only littlefs
|
||||
else if (type == 2) {
|
||||
if (upgradeFS()) {
|
||||
if (upgradeFS(path)) {
|
||||
saveUserDataToFlash();
|
||||
restartEsp();
|
||||
}
|
||||
@@ -23,33 +23,33 @@ void upgrade_firmware(int type) {
|
||||
|
||||
// littlefs and build
|
||||
else if (type == 3) {
|
||||
if (upgradeFS()) {
|
||||
if (upgradeFS(path)) {
|
||||
saveUserDataToFlash();
|
||||
if (upgradeBuild()) {
|
||||
if (upgradeBuild(path)) {
|
||||
restartEsp();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool upgradeFS() {
|
||||
bool upgradeFS(String path) {
|
||||
bool ret = false;
|
||||
WiFiClient wifiClient;
|
||||
SerialPrint("!!!", F("Update"), F("Start upgrade FS..."));
|
||||
SerialPrint("!!!", F("Update"), "Start upgrade FS... " + path);
|
||||
handleUpdateStatus(true, UPDATE_FS_IN_PROGRESS);
|
||||
if (getBinPath("") == "error") {
|
||||
if (path == "") {
|
||||
SerialPrint("E", F("Update"), F("FS Path error"));
|
||||
handleUpdateStatus(true, PATH_ERROR);
|
||||
return ret;
|
||||
}
|
||||
#ifdef ESP8266
|
||||
ESPhttpUpdate.rebootOnUpdate(false);
|
||||
t_httpUpdate_return retFS = ESPhttpUpdate.updateFS(wifiClient, getBinPath("littlefs.bin"));
|
||||
t_httpUpdate_return retFS = ESPhttpUpdate.updateFS(wifiClient, path + "/littlefs.bin");
|
||||
#endif
|
||||
#ifdef ESP32
|
||||
httpUpdate.rebootOnUpdate(false);
|
||||
// обновляем little fs с помощью метода обновления spiffs
|
||||
HTTPUpdateResult retFS = httpUpdate.updateSpiffs(wifiClient, getBinPath("littlefs.bin"));
|
||||
// обновляем little fs с помощью метода обновления spiffs!!!!
|
||||
HTTPUpdateResult retFS = httpUpdate.updateSpiffs(wifiClient, path + "/littlefs.bin");
|
||||
#endif
|
||||
|
||||
// если FS обновилась успешно
|
||||
@@ -59,28 +59,32 @@ bool upgradeFS() {
|
||||
ret = true;
|
||||
} else {
|
||||
handleUpdateStatus(true, UPDATE_FS_FAILED);
|
||||
if (retFS == HTTP_UPDATE_FAILED) {
|
||||
SerialPrint("E", F("Update"), "HTTP_UPDATE_FAILED");
|
||||
} else if (retFS == HTTP_UPDATE_NO_UPDATES) {
|
||||
SerialPrint("E", F("Update"), "HTTP_UPDATE_NO_UPDATES");
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool upgradeBuild() {
|
||||
bool upgradeBuild(String path) {
|
||||
bool ret = false;
|
||||
WiFiClient wifiClient;
|
||||
SerialPrint("!!!", F("Update"), F("Start upgrade BUILD..."));
|
||||
SerialPrint("!!!", F("Update"), "Start upgrade BUILD... " + path);
|
||||
handleUpdateStatus(true, UPDATE_BUILD_IN_PROGRESS);
|
||||
if (getBinPath("") == "error") {
|
||||
if (path == "") {
|
||||
SerialPrint("E", F("Update"), F("Build Path error"));
|
||||
handleUpdateStatus(true, 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)
|
||||
ESPhttpUpdate.rebootOnUpdate(false);
|
||||
t_httpUpdate_return retBuild = ESPhttpUpdate.update(wifiClient, getBinPath("firmware.bin"));
|
||||
t_httpUpdate_return retBuild = ESPhttpUpdate.update(wifiClient, path + "/firmware.bin");
|
||||
#endif
|
||||
#ifdef ESP32
|
||||
httpUpdate.rebootOnUpdate(false);
|
||||
HTTPUpdateResult retBuild = httpUpdate.update(wifiClient, getBinPath("firmware.bin"));
|
||||
HTTPUpdateResult retBuild = httpUpdate.update(wifiClient, path + "/firmware.bin");
|
||||
#endif
|
||||
|
||||
// если BUILD обновился успешно
|
||||
@@ -90,6 +94,11 @@ bool upgradeBuild() {
|
||||
ret = true;
|
||||
} else {
|
||||
handleUpdateStatus(true, UPDATE_BUILD_FAILED);
|
||||
if (retBuild == HTTP_UPDATE_FAILED) {
|
||||
SerialPrint("E", F("Update"), "HTTP_UPDATE_FAILED");
|
||||
} else if (retBuild == HTTP_UPDATE_NO_UPDATES) {
|
||||
SerialPrint("E", F("Update"), "HTTP_UPDATE_NO_UPDATES");
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -100,22 +109,23 @@ void restartEsp() {
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
const String getBinPath(String file) {
|
||||
String path = "error";
|
||||
int targetVersion = 0;
|
||||
String serverip;
|
||||
if (jsonRead(errorsHeapJson, F("chver"), targetVersion)) {
|
||||
if (targetVersion >= 400) {
|
||||
if (jsonRead(settingsFlashJson, F("serverip"), serverip)) {
|
||||
if (serverip != "") {
|
||||
path = jsonReadStr(settingsFlashJson, F("serverip")) + "/iotm/" + String(FIRMWARE_NAME) + "/" + String(targetVersion) + "/" + file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SerialPrint("i", F("Update"), "path: " + path);
|
||||
return path;
|
||||
}
|
||||
// теперь путь к обнавленю прошивки мы получаем из веб интерфейса
|
||||
// const String getBinPath(String file) {
|
||||
// String path = "error";
|
||||
// int targetVersion = 0;
|
||||
// String serverip;
|
||||
// if (jsonRead(errorsHeapJson, F("chver"), targetVersion)) {
|
||||
// if (targetVersion >= 400) {
|
||||
// if (jsonRead(settingsFlashJson, F("serverip"), serverip)) {
|
||||
// if (serverip != "") {
|
||||
// path = jsonReadStr(settingsFlashJson, F("serverip")) + "/iotm/" + String(FIRMWARE_NAME) + "/" + String(targetVersion) + "/" + file;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// SerialPrint("i", F("Update"), "path: " + path);
|
||||
// return path;
|
||||
// }
|
||||
|
||||
void putUserDataToRam() {
|
||||
update.configJson = readFile("config.json", 4096);
|
||||
|
||||
Reference in New Issue
Block a user