mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 14:12:16 +03:00
local sever ota
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
"mqttUser": "rise",
|
||||
"mqttPass": "3hostel3",
|
||||
"serverip": "http://iotmanager.org",
|
||||
"serverlocal": "http://192.168.1.2:5500",
|
||||
"log": 0,
|
||||
"mqttin": 0,
|
||||
"i2c": 0,
|
||||
|
||||
@@ -32,6 +32,10 @@
|
||||
#define FIRMWARE_NAME "esp32_4mb"
|
||||
#endif
|
||||
|
||||
#ifdef esp32_4mb3f
|
||||
#define FIRMWARE_NAME "esp32_4mb3f"
|
||||
#endif
|
||||
|
||||
#ifdef esp32cam_4mb
|
||||
#define FIRMWARE_NAME "esp32cam_4mb"
|
||||
#endif
|
||||
|
||||
@@ -9,6 +9,7 @@ extern bool handleFileRead(String path);
|
||||
extern void handleFileUpload();
|
||||
extern void handleFileDelete();
|
||||
extern void handleFileCreate();
|
||||
extern void handleLocalOTA();
|
||||
extern void handleFileList();
|
||||
//void printDirectory(File dir, String& out);
|
||||
extern void handleStatus();
|
||||
|
||||
@@ -22,7 +22,7 @@ extern bool upgradeFS(String path);
|
||||
extern bool upgradeBuild(String path);
|
||||
extern void restartEsp();
|
||||
|
||||
extern const String getBinPath(String file);
|
||||
extern const String getBinPath();
|
||||
extern void putUserDataToRam();
|
||||
extern void saveUserDataToFlash();
|
||||
extern void saveUpdeteStatus(String key, int val);
|
||||
@@ -232,7 +232,7 @@ lib_deps =
|
||||
${env:esp32_4mb3f_fromitems.lib_deps}
|
||||
lib_ignore = LT_WebSockets
|
||||
build_flags = ${common.build_flags}
|
||||
-Desp32_4mb="esp32_4mb"
|
||||
-Desp32_4mb3f="esp32_4mb3f"
|
||||
-Wl,--wrap=esp_panic_handler
|
||||
framework = arduino
|
||||
board = esp32dev
|
||||
|
||||
@@ -52,7 +52,7 @@ void elementsLoop() {
|
||||
#define COUNTER_ERRORMARKER 4 // количество шагов счетчика
|
||||
#define STEPPER_ERRORMARKER 100000 // размер шага счетчика интервала доверия выполнения блока кода мкс
|
||||
|
||||
#if defined(esp32_4mb) || defined(esp32_16mb) || defined(esp32cam_4mb)
|
||||
#if defined(esp32_4mb) || defined(esp32_4mb3f) || defined(esp32_16mb) || defined(esp32cam_4mb)
|
||||
|
||||
static int IRAM_ATTR initErrorMarkerId = 0; // ИД маркера
|
||||
static int IRAM_ATTR errorMarkerId = 0;
|
||||
@@ -71,14 +71,14 @@ void IRAM_ATTR onTimer() {
|
||||
#endif
|
||||
|
||||
void initErrorMarker(int id) {
|
||||
#if defined(esp32_4mb) || defined(esp32_16mb) || defined(esp32cam_4mb)
|
||||
#if defined(esp32_4mb) || defined(esp32_4mb3f) || defined(esp32_16mb) || defined(esp32cam_4mb)
|
||||
initErrorMarkerId = id;
|
||||
errorMarkerCounter = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void stopErrorMarker(int id) {
|
||||
#if defined(esp32_4mb) || defined(esp32_16mb) || defined(esp32cam_4mb)
|
||||
#if defined(esp32_4mb) || defined(esp32_4mb3f) || defined(esp32_16mb) || defined(esp32cam_4mb)
|
||||
errorMarkerCounter = -1;
|
||||
if (errorMarkerId)
|
||||
SerialPrint("I", "WARNING!", "A lazy (freezing loop more than " + (String)(COUNTER_ERRORMARKER * STEPPER_ERRORMARKER / 1000) + " ms) section has been found! With ID=" + (String)errorMarkerId);
|
||||
@@ -91,7 +91,7 @@ void setup() {
|
||||
#if defined(esp32s2_4mb) || defined(esp32s3_16mb)
|
||||
USB.begin();
|
||||
#endif
|
||||
#if defined(esp32_4mb) || defined(esp32_16mb) || defined(esp32cam_4mb)
|
||||
#if defined(esp32_4mb) || defined(esp32_4mb3f) || defined(esp32_16mb) || defined(esp32cam_4mb)
|
||||
My_timer = timerBegin(0, 80, true);
|
||||
timerAttachInterrupt(My_timer, &onTimer, true);
|
||||
timerAlarmWrite(My_timer, STEPPER_ERRORMARKER, true);
|
||||
|
||||
@@ -121,7 +121,7 @@ String ESP32GetResetReason(uint32_t cpu_no) {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(esp32_4mb) || defined(esp32_16mb) || defined(esp32cam_4mb)
|
||||
#if defined(esp32_4mb) || defined(esp32_4mb3f) || defined(esp32_16mb) || defined(esp32cam_4mb)
|
||||
String ESP_getResetReason(void) {
|
||||
// return ESP32GetResetReason(0); // CPU 0
|
||||
esp_reset_reason_t esp_reason = esp_reset_reason();
|
||||
|
||||
@@ -89,6 +89,8 @@ void standWebServerInit() {
|
||||
// - second callback handles file upload at that location
|
||||
HTTP.on("/edit", HTTP_POST, replyOK, handleFileUpload);
|
||||
|
||||
HTTP.on("/localota", HTTP_GET, handleLocalOTA);
|
||||
|
||||
// Default handler for all URIs not defined above
|
||||
// Use it to read files from filesystem
|
||||
HTTP.onNotFound(handleNotFound);
|
||||
@@ -156,6 +158,10 @@ void handleStatus() {
|
||||
HTTP.send(200, "application/json", json);
|
||||
}
|
||||
|
||||
void handleLocalOTA() {
|
||||
upgrade_firmware(3, "local");
|
||||
}
|
||||
|
||||
#ifdef ESP32
|
||||
String getContentType(String filename) {
|
||||
if (HTTP.hasArg("download")) {
|
||||
|
||||
@@ -44,6 +44,8 @@ bool upgradeFS(String path) {
|
||||
SerialPrint("E", F("Update"), F("FS Path error"));
|
||||
saveUpdeteStatus("fs", PATH_ERROR);
|
||||
return ret;
|
||||
} else if (path == "local"){
|
||||
path = getBinPath();
|
||||
}
|
||||
#ifdef ESP8266
|
||||
ESPhttpUpdate.rebootOnUpdate(false);
|
||||
@@ -58,14 +60,17 @@ bool upgradeFS(String path) {
|
||||
// если FS обновилась успешно
|
||||
if (retFS == HTTP_UPDATE_OK) {
|
||||
SerialPrint("!!!", F("Update"), F("FS upgrade done!"));
|
||||
//HTTP.send(200, "text/plain", "FS upgrade done!");
|
||||
saveUpdeteStatus("fs", UPDATE_COMPLETED);
|
||||
ret = true;
|
||||
} else {
|
||||
saveUpdeteStatus("fs", UPDATE_FAILED);
|
||||
if (retFS == HTTP_UPDATE_FAILED) {
|
||||
SerialPrint("E", F("Update"), "HTTP_UPDATE_FAILED");
|
||||
HTTP.send(200, "text/plain", "FS UPDATE_FAILED! DELETE /localota !!!");
|
||||
} else if (retFS == HTTP_UPDATE_NO_UPDATES) {
|
||||
SerialPrint("E", F("Update"), "HTTP_UPDATE_NO_UPDATES");
|
||||
SerialPrint("E", F("Update"), "HTTP_UPDATE_NO_UPDATES! DELETE /localota !!!");
|
||||
//HTTP.send(200, "text/plain", "NO_UPDATES");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -82,6 +87,8 @@ bool upgradeBuild(String path) {
|
||||
SerialPrint("E", F("Update"), F("Build Path error"));
|
||||
saveUpdeteStatus("build", PATH_ERROR);
|
||||
return ret;
|
||||
} else if (path == "local"){
|
||||
path = getBinPath();
|
||||
}
|
||||
#if defined(esp8266_4mb) || defined(esp8266_16mb) || defined(esp8266_1mb) || defined(esp8266_1mb_ota) || defined(esp8266_2mb) || defined(esp8266_2mb_ota)
|
||||
ESPhttpUpdate.rebootOnUpdate(false);
|
||||
@@ -95,14 +102,17 @@ bool upgradeBuild(String path) {
|
||||
// если BUILD обновился успешно
|
||||
if (retBuild == HTTP_UPDATE_OK) {
|
||||
SerialPrint("!!!", F("Update"), F("BUILD upgrade done!"));
|
||||
HTTP.send(200, "text/plain", "BUILD upgrade done! DELETE /localota !!!");
|
||||
saveUpdeteStatus("build", UPDATE_COMPLETED);
|
||||
ret = true;
|
||||
} else {
|
||||
saveUpdeteStatus("build", UPDATE_FAILED);
|
||||
if (retBuild == HTTP_UPDATE_FAILED) {
|
||||
SerialPrint("E", F("Update"), "HTTP_UPDATE_FAILED");
|
||||
HTTP.send(200, "text/plain", "UPDATE_FAILED! DELETE /localota !!!");
|
||||
} else if (retBuild == HTTP_UPDATE_NO_UPDATES) {
|
||||
SerialPrint("E", F("Update"), "HTTP_UPDATE_NO_UPDATES");
|
||||
HTTP.send(200, "text/plain", "NO_UPDATES! DELETE /localota !!!");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -115,23 +125,23 @@ void restartEsp() {
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
// теперь путь к обнавленю прошивки мы получаем из веб интерфейса
|
||||
// const String getBinPath(String file) {
|
||||
// String path = "error";
|
||||
// int targetVersion = 0;
|
||||
// String serverip;
|
||||
//теперь путь к обнавленю прошивки мы получаем из веб интерфейса
|
||||
const String getBinPath() {
|
||||
String path = "error";
|
||||
int targetVersion = 400; //HACKFUCK local OTA version in PrepareServer.py
|
||||
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;
|
||||
if (targetVersion >= 400) {
|
||||
if (jsonRead(settingsFlashJson, F("serverlocal"), serverip)) {
|
||||
if (serverip != "") {
|
||||
path = jsonReadStr(settingsFlashJson, F("serverlocal")) + "/iotm/" + String(FIRMWARE_NAME) + "/" + String(targetVersion) + "/";
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
SerialPrint("i", F("Update"), "server local: " + path);
|
||||
return path;
|
||||
}
|
||||
|
||||
// https://t.me/IoTmanager/128814/164752 - убрал ограничение
|
||||
void putUserDataToRam() {
|
||||
|
||||
Reference in New Issue
Block a user