handle OTA aborted cases

This commit is contained in:
technyon
2023-02-11 10:28:11 +01:00
parent 1181c821a7
commit b91908343d
2 changed files with 24 additions and 4 deletions

View File

@@ -13,6 +13,8 @@ enum class RestartReason
ConfigurationUpdated, ConfigurationUpdated,
RestartTimer, RestartTimer,
OTATimeout, OTATimeout,
OTAAborted,
OTAUnknownState,
DeviceUnpaired, DeviceUnpaired,
}; };

View File

@@ -1042,23 +1042,41 @@ void WebCfgServer::handleOtaUpload()
return; return;
} }
if (upload.status == UPLOAD_FILE_START) { if (upload.status == UPLOAD_FILE_START)
{
String filename = upload.filename; String filename = upload.filename;
if (!filename.startsWith("/")) { if (!filename.startsWith("/"))
{
filename = "/" + filename; filename = "/" + filename;
} }
_otaStartTs = millis(); _otaStartTs = millis();
esp_task_wdt_init(30, false); esp_task_wdt_init(30, false);
_network->disableAutoRestarts(); _network->disableAutoRestarts();
Log->print("handleFileUpload Name: "); Log->println(filename); Log->print("handleFileUpload Name: "); Log->println(filename);
} else if (upload.status == UPLOAD_FILE_WRITE) { }
else if (upload.status == UPLOAD_FILE_WRITE)
{
_transferredSize = _transferredSize + upload.currentSize; _transferredSize = _transferredSize + upload.currentSize;
Log->println(_transferredSize); Log->println(_transferredSize);
_ota.updateFirmware(upload.buf, upload.currentSize); _ota.updateFirmware(upload.buf, upload.currentSize);
} else if (upload.status == UPLOAD_FILE_END) { } else if (upload.status == UPLOAD_FILE_END)
{
Log->println(); Log->println();
Log->print("handleFileUpload Size: "); Log->println(upload.totalSize); Log->print("handleFileUpload Size: "); Log->println(upload.totalSize);
} }
else if(upload.status == UPLOAD_FILE_ABORTED)
{
Log->println();
Log->println("OTA aborted, restarting ESP.");
restartEsp(RestartReason::OTAAborted);
}
else
{
Log->println();
Log->print("OTA unknown state: ");
Log->println((int)upload.status);
restartEsp(RestartReason::OTAUnknownState);
}
} }
void WebCfgServer::sendCss() void WebCfgServer::sendCss()