2020-03-01 20:41:16 +03:00
|
|
|
|
void initUpgrade() {
|
2020-03-27 15:48:17 +01:00
|
|
|
|
#ifdef ESP8266
|
|
|
|
|
|
if (WiFi.status() == WL_CONNECTED) last_version = getURL("http://91.204.228.124:1100/update/esp8266/version.txt");
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#ifdef ESP32
|
|
|
|
|
|
if (WiFi.status() == WL_CONNECTED) last_version = getURL("http://91.204.228.124:1100/update/esp32/version.txt");
|
|
|
|
|
|
#endif
|
2020-06-11 22:51:34 +02:00
|
|
|
|
jsonWriteStr(configSetupJson, "last_version", last_version);
|
2020-03-27 15:48:17 +01:00
|
|
|
|
Serial.print("[i] Last firmware version: ");
|
|
|
|
|
|
Serial.println(last_version);
|
2020-03-04 00:27:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-05 01:52:02 +02:00
|
|
|
|
void do_upgrade_url() {
|
|
|
|
|
|
if (upgrade_url) {
|
|
|
|
|
|
upgrade_url = false;
|
2020-03-22 22:41:52 +01:00
|
|
|
|
#ifdef ESP32
|
|
|
|
|
|
last_version = getURL("http://91.204.228.124:1100/update/esp32/version.txt");
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#ifdef ESP8266
|
|
|
|
|
|
last_version = getURL("http://91.204.228.124:1100/update/esp8266/version.txt");
|
|
|
|
|
|
#endif
|
2020-06-12 15:34:30 +02:00
|
|
|
|
jsonWriteStr(configSetupJson, "last_version", last_version);
|
2020-03-22 22:41:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-04 00:27:35 +03:00
|
|
|
|
void upgrade_firmware() {
|
|
|
|
|
|
|
|
|
|
|
|
String scenario_for_update;
|
|
|
|
|
|
String config_for_update;
|
|
|
|
|
|
String configSetup_for_update;
|
2020-04-22 20:35:50 +02:00
|
|
|
|
scenario_for_update = readFile("firmware.s.txt", 4000);
|
|
|
|
|
|
config_for_update = readFile("firmware.c.txt", 4000);
|
2020-06-11 22:51:34 +02:00
|
|
|
|
configSetup_for_update = configSetupJson;
|
2020-03-04 00:27:35 +03:00
|
|
|
|
|
|
|
|
|
|
Serial.println("Start upgrade SPIFFS, please wait...");
|
2020-03-16 00:00:59 +01:00
|
|
|
|
|
2020-03-04 00:27:35 +03:00
|
|
|
|
WiFiClient client_for_upgrade;
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ESP32
|
|
|
|
|
|
httpUpdate.rebootOnUpdate(false);
|
|
|
|
|
|
t_httpUpdate_return ret = httpUpdate.updateSpiffs(client_for_upgrade, "http://91.204.228.124:1100/update/esp32/esp32-esp8266_iot-manager_modules_firmware.spiffs.bin");
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#ifdef ESP8266
|
|
|
|
|
|
ESPhttpUpdate.rebootOnUpdate(false);
|
|
|
|
|
|
t_httpUpdate_return ret = ESPhttpUpdate.updateSpiffs(client_for_upgrade, "http://91.204.228.124:1100/update/esp8266/esp32-esp8266_iot-manager_modules_firmware.spiffs.bin");
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
if (ret == HTTP_UPDATE_OK) {
|
|
|
|
|
|
|
2020-03-30 01:45:42 +02:00
|
|
|
|
writeFile("firmware.s.txt", scenario_for_update);
|
|
|
|
|
|
writeFile("firmware.c.txt", config_for_update);
|
2020-03-04 00:27:35 +03:00
|
|
|
|
writeFile("config.json", configSetup_for_update);
|
|
|
|
|
|
saveConfig();
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println("SPIFFS upgrade done!");
|
|
|
|
|
|
Serial.println("Start upgrade BUILD, please wait...");
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ESP32
|
2020-03-16 00:00:59 +01:00
|
|
|
|
//httpUpdate.rebootOnUpdate(true);
|
2020-03-04 00:27:35 +03:00
|
|
|
|
t_httpUpdate_return ret = httpUpdate.update(client_for_upgrade, "http://91.204.228.124:1100/update/esp32/esp32-esp8266_iot-manager_modules_firmware.ino.bin");
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#ifdef ESP8266
|
2020-03-16 00:00:59 +01:00
|
|
|
|
//ESPhttpUpdate.rebootOnUpdate(true);
|
2020-03-04 00:27:35 +03:00
|
|
|
|
t_httpUpdate_return ret = ESPhttpUpdate.update(client_for_upgrade, "http://91.204.228.124:1100/update/esp8266/esp32-esp8266_iot-manager_modules_firmware.ino.bin");
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2020-03-16 00:00:59 +01:00
|
|
|
|
if (ret == HTTP_UPDATE_OK) {
|
2020-06-12 15:34:30 +02:00
|
|
|
|
|
2020-03-16 00:00:59 +01:00
|
|
|
|
Serial.println("BUILD upgrade done!");
|
|
|
|
|
|
Serial.println("Restart ESP....");
|
|
|
|
|
|
ESP.restart();
|
2020-04-22 20:35:50 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
Serial.println("!!!!BUILD upgrade ERROR");
|
2020-03-16 00:00:59 +01:00
|
|
|
|
}
|
2020-04-22 20:35:50 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
Serial.println("!!!!SPIFFS upgrade ERROR");
|
2020-03-04 00:27:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-05 01:52:02 +02:00
|
|
|
|
void do_upgrade() {
|
|
|
|
|
|
if (upgrade) {
|
|
|
|
|
|
upgrade = false;
|
2020-03-04 01:56:24 +03:00
|
|
|
|
upgrade_firmware();
|
2020-03-04 00:27:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
void upgrade_status(t_httpUpdate_return set) {
|
|
|
|
|
|
switch (set) {
|
|
|
|
|
|
case HTTP_UPDATE_FAILED:
|
|
|
|
|
|
Serial.printf("UPDATE_FAILED Error (%d): %s", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str());
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case HTTP_UPDATE_NO_UPDATES:
|
|
|
|
|
|
Serial.println("NO_UPDATES");
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case HTTP_UPDATE_OK:
|
|
|
|
|
|
Serial.println("HTTP_UPDATE_OK");
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-03-01 20:41:16 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
// ----------------------- Обновление с сайта
|
|
|
|
|
|
void webUpgrade() {
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ESP8266
|
|
|
|
|
|
String spiffsData = "http://91.204.228.124:1100/update/esp8266/esp32-esp8266_iot-manager_modules_firmware.spiffs.bin";
|
|
|
|
|
|
String buildData = "http://91.204.228.124:1100/update/esp8266/esp32-esp8266_iot-manager_modules_firmware.ino.bin";
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ESP32
|
|
|
|
|
|
String spiffsData = "http://91.204.228.124:1100/update/esp32/esp32-esp8266_iot-manager_modules_firmware.spiffs.bin";
|
|
|
|
|
|
String buildData = "http://91.204.228.124:1100/update/esp32/esp32-esp8266_iot-manager_modules_firmware.ino.bin";
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
if (spiffsData != "") { // Если нужно прошить FS
|
|
|
|
|
|
String scenario_for_update;
|
|
|
|
|
|
String config_for_update;
|
|
|
|
|
|
String configSetup_for_update;
|
|
|
|
|
|
Serial.println(spiffsData);
|
2020-03-30 01:45:42 +02:00
|
|
|
|
scenario_for_update = readFile("firmware.s.txt", 2048);
|
2020-03-01 20:41:16 +03:00
|
|
|
|
config_for_update = readFile("config.all.txt", 2048);
|
|
|
|
|
|
configSetup_for_update = configSetup;
|
|
|
|
|
|
ESPhttpUpdate.rebootOnUpdate(false); // Отключим перезагрузку после обновления
|
|
|
|
|
|
updateHTTP(spiffsData, true);
|
2020-03-30 01:45:42 +02:00
|
|
|
|
writeFile("firmware.s.txt", scenario_for_update);
|
2020-03-01 20:41:16 +03:00
|
|
|
|
writeFile("config.all.txt", config_for_update);
|
|
|
|
|
|
writeFile("config.json", configSetup_for_update);
|
|
|
|
|
|
saveConfig();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (buildData != "") { // Если нужно прошить build
|
|
|
|
|
|
Serial.println(buildData);
|
|
|
|
|
|
ESPhttpUpdate.rebootOnUpdate(true); // Включим перезагрузку после обновления
|
|
|
|
|
|
updateHTTP(buildData, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// ------------------ Обновление по url
|
|
|
|
|
|
void updateHTTP(String url, boolean mode) {
|
|
|
|
|
|
if (url == "") return;
|
|
|
|
|
|
ESPhttpUpdate.setLedPin(LED_BUILTIN, LOW);
|
|
|
|
|
|
if (mode) {
|
|
|
|
|
|
Serial.println("Update Spiffs...");
|
|
|
|
|
|
t_httpUpdate_return ret = ESPhttpUpdate.updateSpiffs(url);
|
|
|
|
|
|
UpdateStatus(ret , "Spiffs");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Serial.println("Update Build...");
|
|
|
|
|
|
t_httpUpdate_return ret = ESPhttpUpdate.update(url);
|
|
|
|
|
|
UpdateStatus(ret , "build");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
void UpdateStatus(t_httpUpdate_return set, String mode) {
|
|
|
|
|
|
|
|
|
|
|
|
switch (set) {
|
|
|
|
|
|
|
|
|
|
|
|
case HTTP_UPDATE_FAILED:
|
|
|
|
|
|
Serial.println(mode + "_FAILED");
|
|
|
|
|
|
var = "{}";
|
2020-03-27 15:48:17 +01:00
|
|
|
|
jsonWriteStr(var, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>_FAILED");
|
|
|
|
|
|
jsonWriteStr(var, "class", "pop-up");
|
2020-03-01 20:41:16 +03:00
|
|
|
|
//request->send(200, "text/text", var);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case HTTP_UPDATE_NO_UPDATES:
|
|
|
|
|
|
Serial.println(mode + "_NO_UPDATES");
|
|
|
|
|
|
var = "{}";
|
2020-03-27 15:48:17 +01:00
|
|
|
|
jsonWriteStr(var, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>_NO_UPDATES");
|
|
|
|
|
|
jsonWriteStr(var, "class", "pop-up");
|
2020-03-01 20:41:16 +03:00
|
|
|
|
//request->send(200, "text/text", var);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case HTTP_UPDATE_OK:
|
|
|
|
|
|
Serial.println(mode + "_UPDATE_OK");
|
|
|
|
|
|
var = "{}";
|
2020-03-27 15:48:17 +01:00
|
|
|
|
jsonWriteStr(var, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>_UPDATE_OK");
|
|
|
|
|
|
jsonWriteStr(var, "class", "pop-up");
|
2020-03-01 20:41:16 +03:00
|
|
|
|
//request->send(200, "text/text", var);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
*/
|