Improved OTA (empty firmware directory)

This commit is contained in:
jomjol
2022-11-05 11:33:26 +01:00
parent 8c6805ec7c
commit 885cd71b80
3 changed files with 29 additions and 3 deletions

View File

@@ -328,6 +328,23 @@ esp_err_t handler_ota_update(httpd_req_t *req)
}; };
if (_task.compare("emptyfirmwaredir") == 0)
{
ESP_LOGD(TAGPARTOTA, "Start empty directory /firmware");
delete_all_in_directory("/sdcard/firmware");
std::string zw = "firmware directory deleted - v2\n";
ESP_LOGD(TAGPARTOTA, "%s", zw.c_str());
printf("Ausgabe: %s\n", zw.c_str());
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_send(req, zw.c_str(), strlen(zw.c_str()));
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0);
ESP_LOGD(TAGPARTOTA, "Done empty directory /firmware");
return ESP_OK;
}
if (_task.compare("update") == 0) if (_task.compare("update") == 0)
{ {
std::string filetype = toUpper(getFileType(fn)); std::string filetype = toUpper(getFileType(fn));
@@ -451,6 +468,14 @@ esp_err_t handler_ota_update(httpd_req_t *req)
return ESP_OK; return ESP_OK;
} }
string zw = "ota without parameter - should not be the case!";
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_send(req, zw.c_str(), strlen(zw.c_str()));
httpd_resp_send_chunk(req, NULL, 0);
ESP_LOGE(TAGPARTOTA, "ota without parameter - should not be the case!");
/*
const char* resp_str; const char* resp_str;
KillTFliteTasks(); KillTFliteTasks();
@@ -469,6 +494,7 @@ esp_err_t handler_ota_update(httpd_req_t *req)
#ifdef DEBUG_DETAIL_ON #ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_ota_update - Done"); LogFile.WriteHeapInfo("handler_ota_update - Done");
#endif #endif
*/
return ESP_OK; return ESP_OK;
}; };

View File

@@ -13,7 +13,7 @@ function getbasepath(){
{ {
// host = "http://192.168.2.219"; // jomjol interner test // host = "http://192.168.2.219"; // jomjol interner test
// host = "http://192.168.178.46"; // jomjol interner test // host = "http://192.168.178.46"; // jomjol interner test
host = "http://192.168.178.46"; // jomjol interner Real host = "http://192.168.178.44"; // jomjol interner Real
// host = "http://192.168.43.191"; // host = "http://192.168.43.191";
// host = "."; // jomjol interner localhost // host = "."; // jomjol interner localhost

View File

@@ -140,7 +140,7 @@ function prepareOnServer() {
var nameneu = document.getElementById("newfile").value; var nameneu = document.getElementById("newfile").value;
filePath = nameneu.split(/[\\\/]/).pop(); filePath = nameneu.split(/[\\\/]/).pop();
/* first delete the old firmware */ /* first delete the old firmware AND empty the /firmware directory*/
xhttp.onreadystatechange = function() { xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4) { if (xhttp.readyState == 4) {
stopProgressTimer(); stopProgressTimer();
@@ -159,7 +159,7 @@ function prepareOnServer() {
startProgressTimer("Server preparations..."); startProgressTimer("Server preparations...");
var _toDo = basepath + "/ota?delete=" + filePath; var _toDo = basepath + "/ota?task=emptyfirmwaredir";
xhttp.open("GET", _toDo, true); xhttp.open("GET", _toDo, true);
xhttp.send(); xhttp.send();
} }