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

Merge pull request #1073 from caco3/improve-ota

Improve ota
jomjol 3 лет назад
Родитель
Сommit
0ffaf99e10

+ 2 - 2
code/components/jomjol_fileserver_ota/server_file.cpp

@@ -49,8 +49,8 @@ extern "C" {
 
 /* Max size of an individual file. Make sure this
  * value is same as that set in upload_script.html */
-#define MAX_FILE_SIZE   (2000*1024) // 200 KB
-#define MAX_FILE_SIZE_STR "2000KB"
+#define MAX_FILE_SIZE   (8000*1024) // 8 MB
+#define MAX_FILE_SIZE_STR "8MB"
 
 
 /* Scratch buffer size */

+ 8 - 3
code/components/jomjol_fileserver_ota/server_ota.cpp

@@ -99,6 +99,11 @@ static bool ota_update_task(std::string fn)
     int data_read;     
 
     FILE* f = OpenFileAndWait(fn.c_str(), "rb");     // vorher  nur "r"
+
+    if (f == NULL) { // File does not exist
+        return false;
+    }
+
     data_read = fread(ota_write_data, 1, BUFFSIZE, f);
 
     while (data_read > 0) {
@@ -435,7 +440,7 @@ esp_err_t handler_ota_update(httpd_req_t *req)
         int _result = stat(fn.c_str(), &file_stat);
         printf("Ergebnis %d\n", _result);
         if (_result == 0) {
-            printf("Deleting file : %s", fn.c_str());
+            printf("Deleting file : %s\n", fn.c_str());
             /* Delete file */
             unlink(fn.c_str());
         }
@@ -457,11 +462,11 @@ esp_err_t handler_ota_update(httpd_req_t *req)
     gpio_handler_deinit();
     if (ota_update_task(fn))
     {
-        resp_str = "Firmware Update Successfull!<br><br>You can restart now.";
+        resp_str = "Firmware Update Successfull! You can restart now.";
     }
     else
     {
-        resp_str = "Error during Firmware Update!!!<br><br>Please check console output.";
+        resp_str = "Error during Firmware Update!!! Please check console output.";
     }
 
     httpd_resp_send(req, resp_str, strlen(resp_str));  

+ 10 - 1
code/components/jomjol_helper/Helper.cpp

@@ -88,8 +88,17 @@ void memCopyGen(uint8_t* _source, uint8_t* _target, int _size)
 
 FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec)
 {
+	FILE *pfile;
+
 	printf("open file %s in mode %s\n", nm, _mode);
-	FILE *pfile = fopen(nm, _mode);
+
+	if ((pfile = fopen(nm, _mode)) != NULL) {
+		printf("File %s successfully opened\n", nm);
+	}
+	else {
+		printf("Error: file %s does not exist!\n", nm);
+		return NULL;
+	}
 
 /*
 	if (pfile == NULL)

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

@@ -160,7 +160,7 @@ function upload() {
 	
 
     /* Max size of an individual file. Make sure this
-     * value is same as that set in file_server.c */
+     * value is same as that set in server_file.c */
     var MAX_FILE_SIZE = 8000*1024;
     var MAX_FILE_SIZE_STR = "8MB";