From 492690ecf196fe84570e770aaae775f1066cb326 Mon Sep 17 00:00:00 2001 From: technyon Date: Thu, 21 Jul 2022 20:23:56 +0200 Subject: [PATCH] restart ESP when OTA doesn't complete --- WebCfgServer.cpp | 16 ++++++++++++---- WebCfgServer.h | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/WebCfgServer.cpp b/WebCfgServer.cpp index 2bc9250..a10bb90 100644 --- a/WebCfgServer.cpp +++ b/WebCfgServer.cpp @@ -381,6 +381,13 @@ bool WebCfgServer::processArgs(String& message) void WebCfgServer::update() { + if(_otaStartTs > 0 && (millis() - _otaStartTs) > 120000) + { + Serial.println(F("OTA time out, restarting")); + delay(200); + ESP.restart(); + } + if(!_enabled) return; _server.handleClient(); @@ -783,7 +790,8 @@ void WebCfgServer::waitAndProcess(const bool blocking, const uint32_t duration) void WebCfgServer::handleOtaUpload() { - if (_server.uri() != "/uploadota") { + if (_server.uri() != "/uploadota") + { return; } if(millis() < 60000) @@ -791,9 +799,6 @@ void WebCfgServer::handleOtaUpload() return; } - esp_task_wdt_init(30, false); - _network->disableAutoRestarts(); - HTTPUpload& upload = _server.upload(); if(upload.filename == "") @@ -807,6 +812,9 @@ void WebCfgServer::handleOtaUpload() if (!filename.startsWith("/")) { filename = "/" + filename; } + _otaStartTs = millis(); + esp_task_wdt_init(30, false); + _network->disableAutoRestarts(); Serial.print("handleFileUpload Name: "); Serial.println(filename); } else if (upload.status == UPLOAD_FILE_WRITE) { _transferredSize = _transferredSize + upload.currentSize; diff --git a/WebCfgServer.h b/WebCfgServer.h index 859b857..09b40da 100644 --- a/WebCfgServer.h +++ b/WebCfgServer.h @@ -74,6 +74,7 @@ private: char _credPassword[31] = {0}; bool _allowRestartToPortal = false; uint32_t _transferredSize = 0; + unsigned long _otaStartTs = 0; String _hostname; String _confirmCode = "----";