Просмотр исходного кода

Improved OTA (empty firmware directory)

jomjol 3 лет назад
Родитель
Сommit
885cd71b80

+ 26 - 0
code/components/jomjol_fileserver_ota/server_ota.cpp

@@ -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)
     {
         std::string filetype = toUpper(getFileType(fn));
@@ -451,6 +468,14 @@ esp_err_t handler_ota_update(httpd_req_t *req)
         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;    
 
     KillTFliteTasks();
@@ -469,6 +494,7 @@ esp_err_t handler_ota_update(httpd_req_t *req)
 #ifdef DEBUG_DETAIL_ON 
     LogFile.WriteHeapInfo("handler_ota_update - Done");    
 #endif
+*/
 
     return ESP_OK;
 };

+ 1 - 1
sd-card/html/gethost.js

@@ -13,7 +13,7 @@ function getbasepath(){
     {
 //        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 Real
+        host = "http://192.168.178.44";          // jomjol interner Real
 //        host = "http://192.168.43.191";
 //        host = ".";                           // jomjol interner localhost   
 

+ 2 - 2
sd-card/html/ota_page.html

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