jomjol 5 years ago
parent
commit
341e9f1593

+ 5 - 0
README.md

@@ -27,6 +27,11 @@ A 3d-printable housing can be found here: https://www.thingiverse.com/thing:4571
 
 
 
+##### 1.1.1 (2020-09-07)
+
+* Improved update page for the web server (`/html` can be updated via a zip-file, which is provided in `/firmware/html.zip`)
+  **Attention: beside the `firmware.bin`, also the content of `/html` needs to be updated!**
+
 ##### 1.1.0 (2020-09-06)
 
 * Implementation of "delete complete directory"

+ 3 - 1
code/lib/jomjol_fileserver_ota/server_ota.cpp

@@ -338,7 +338,9 @@ esp_err_t handler_ota_update(httpd_req_t *req)
         std::string in, out, zw;
 
         in = "/sdcard/firmware/html.zip";
-        out = "/sdcard/html2/";
+        out = "/sdcard/html/";
+
+        delete_all_in_directory(out);
 
         unzip(in, out);
         zw = "HTML Update Successfull!<br><br>No reboot necessary";

+ 8 - 1
code/src/server_main.cpp

@@ -105,6 +105,7 @@ esp_err_t hello_main_handler(httpd_req_t *req)
     char filepath[50];
     struct stat file_stat;
     printf("uri: %s\n", req->uri);
+    int _pos;
 
     char *base_path = (char*) req->user_ctx;
     std::string filetosend(base_path);
@@ -120,9 +121,15 @@ esp_err_t hello_main_handler(httpd_req_t *req)
     else
     {
         filetosend = filetosend + "/html" + std::string(req->uri);
+        _pos = filetosend.find("?");
+        if (_pos > -1){
+            filetosend = filetosend.substr(0, _pos);
+        }
     }
+
+    printf("Filename: %s\n", filename);
     
-    printf("File to upload: %s\n", filetosend.c_str());    
+    printf("File requested: %s\n", filetosend.c_str());    
 
     if (!filename) {
         ESP_LOGE(TAG, "Filename is too long");

BIN
firmware/bootloader.bin


BIN
firmware/firmware.bin


BIN
firmware/html.zip


+ 4 - 1
sd-card/html/edit_digits.html

@@ -152,7 +152,10 @@ function ChangeSelection(){
 
 function SaveToConfig(){
     SaveROIToConfig(ROIInfo, "[Digits]", basepath);
-    location.reload();
+//    location.reload();
+//    parent.window.location.reload(true);
+//    window.location = location.href + '?session=' + Math.floor((Math.random() * 1000000) + 1);  
+    UpdatePage();  
 }
 
 

+ 2 - 7
sd-card/html/edit_reference.html

@@ -101,13 +101,8 @@
                 setPreRotate(document.getElementById("prerotateangle").value);
                 UpdateConfigFile(basepath);
                 var canvas = document.getElementById("canvas");
-                var okay = SaveCanvasToImage(canvas, "/config/reference.jpg", true, basepath);
-                if (okay) {
-                    alert("Update \"reference.jpg\" successfull!")
-                }
-                else {
-                    alert("Error on update \"reference.jpg\"!")
-                }
+                SaveCanvasToImage(canvas, "/config/reference.jpg", true, basepath);
+                showReference();
             }
         }
 

+ 6 - 0
sd-card/html/gethost.js

@@ -13,3 +13,9 @@ function getbasepath(){
     }
     return host;
 }
+
+function UpdatePage(){
+    var zw = location.href;
+    zw = zw.substr(0, zw.indexOf("?"));
+    window.location = zw + '?session=' + Math.floor((Math.random() * 1000000) + 1);   
+}

+ 223 - 30
sd-card/html/ota_page.html

@@ -10,41 +10,151 @@
 </head>
 
 <body>
+<h3>It is strongly recommended to update firmware and content of /html directory on SD-card at the same time!</h3>
+<h2>1. Firmware Update</h2>
 <table class="fixed" border="0">
-    <td>
-        <table border="0">
-            <tr>
-                <td>
-                    <label for="newfile">Select the firmware file</label>
-                </td>
-                <td colspan="2">
-                    <input id="newfile" type="file" onchange="setpath()" style="width:100%;">
-                </td>
-            </tr>
-            <tr>
-                <td>
-                    <label for="filepath">Set path on server</label>
-                </td>
-                <td>
-                    <input id="filepath" type="text" style="width:100%;" readonly>
-                </td>
-                <td>
-                    <button id="upload" type="button" onclick="upload()">Upload</button>
-                </td>
-            </tr>
-        </table>
-    </td></tr>
+    <tr>
+        <td>
+            <table border="0">
+                <tr>
+                    <td>
+                        <label for="newfile">Select the firmware file</label>
+                    </td>
+                    <td colspan="2">
+                        <input id="newfile" type="file" onchange="setpath()" style="width:100%;">
+                    </td>
+                </tr>
+                <tr>
+                    <td>
+                        <label for="filepath">Set path on server</label>
+                    </td>
+                    <td>
+                        <input id="filepath" type="text" style="width:100%;" readonly>
+                    </td>
+                    <td>
+                        <button id="upload" type="button" onclick="upload()">Upload</button>
+                    </td>
+                </tr>
+            </table>
+        </td>
+    </tr>
 	<tr>
 		<td>
-			<button id="upload" type="button" onclick="doUpdate()">Flash the update</button> (Takes about 60s)
+			<button id="doUpdate" type="button" onclick="doUpdate()">Flash the firmware</button> (Takes about 60s)
 		</td>
 	</tr>
 </table>
 
-<script>
+<h2>2. Update /html directory</h2>
+<table class="fixed" border="0">
+    <tr>
+        <td>
+            <table border="0">
+                <tr>
+                    <td>
+                        <label for="newfilehtml">Select the zipped /html content</label>
+                    </td>
+                    <td colspan="2">
+                        <input id="newfilehtml" type="file" onchange="setpathhtml()" style="width:100%;">
+                    </td>
+                </tr>
+                <tr>
+                    <td>
+                        <label for="filepathhtml">Set path on server</label>
+                    </td>
+                    <td>
+                        <input id="filepathhtml" type="text" style="width:100%;" readonly>
+                    </td>
+                    <td>
+                        <button id="uploadhtml" type="button" onclick="uploadhtml()">Upload</button>
+                    </td>
+                </tr>
+            </table>
+        </td>
+    </tr>
+	<tr>
+		<td>
+			<button id="doUpdatehtml" type="button" onclick="doUpdatehtml()">Update "/html" directory</button>
+		</td>
+	</tr>
+</table>
+<h2>3. Reboot</h2>
+<table class="fixed" border="0">
+	<tr>
+		<td>
+			<button id="reboot" type="button" onclick="doReboot()">Reboot to activate updates</button>
+		</td>
+	</tr>
+</table>
+
+<script type="text/javascript" src="./gethost.js"></script> 
+
+
+<script language="JavaScript">
+
+function init(){
+    document.getElementById("reboot").disabled = true;
+    document.getElementById("upload").disabled = true;
+    document.getElementById("uploadhtml").disabled = true;    
+    document.getElementById("doUpdate").disabled = true;
+    document.getElementById("doUpdatehtml").disabled = true;
+}
+
 function doUpdate() {
 	if (confirm("Are you sure to update the firmware?")) {
 		var stringota = "/ota?file=firmware.bin";
+        
+        var xhttp = new XMLHttpRequest();
+	
+        xhttp.onreadystatechange = function() {
+            if (xhttp.readyState == 4) {
+                if (xhttp.status == 200) {
+                    document.getElementById("reboot").disabled = false;
+                    alert("Flash successfull - Reboot necessary to make changes active.");
+                    /* keine Reaktion, damit sich das Dokument nicht ändert */
+                } else if (xhttp.status == 0) {
+                    alert("Server closed the connection abruptly!");
+                    UpdatePage();
+                } else {
+                    alert(xhttp.status + " Error!\n" + xhttp.responseText);
+                    UpdatePage();
+                }
+            }
+        };
+        xhttp.open("GET", stringota, true);
+        xhttp.send();        
+	}
+}
+
+function doUpdatehtml() {
+	if (confirm("Are you sure to update the /html content?")) {
+		var stringota = "/ota?task=unziphtml";
+        
+        var xhttp = new XMLHttpRequest();
+	
+        xhttp.onreadystatechange = function() {
+            if (xhttp.readyState == 4) {
+                if (xhttp.status == 200) {
+                    document.getElementById("reboot").disabled = false;
+                    alert("Update /html successful!");
+                    /* keine Reaktion, damit sich das Dokument nicht ändert */
+                } else if (xhttp.status == 0) {
+                    alert("Server closed the connection abruptly!");
+                    UpdatePage();
+                } else {
+                    alert(xhttp.status + " Error!\n" + xhttp.responseText);
+                    UpdatePage();
+                }
+            }
+        };
+        xhttp.open("GET", stringota, true);
+        xhttp.send();
+	}
+}
+
+function doReboot() {
+	if (confirm("Are you sure you want to reboot the ESP32?")) {
+		var stringota = "/reboot";
 		window.location = stringota;
 		window.location.href = stringota;
 		window.location.assign(stringota);
@@ -55,8 +165,16 @@ function doUpdate() {
 function setpath() {
     var fileserverpraefix = "/firmware/firmware.bin";
     document.getElementById("filepath").value = fileserverpraefix;
+    document.getElementById("upload").disabled = false;
+}
+
+function setpathhtml() {
+    var fileserverpraefix = "/firmware/html.zip";
+    document.getElementById("filepathhtml").value = fileserverpraefix;
+    document.getElementById("uploadhtml").disabled = false;
 }
 
+
 function upload() {
 	var xhttp = new XMLHttpRequest();
 	
@@ -67,10 +185,10 @@ function upload() {
 				/* keine Reaktion, damit sich das Dokument nicht ändert */
 			} else if (xhttp.status == 0) {
 				alert("Server closed the connection abruptly!");
-				location.reload()
+				UpdatePage();
 			} else {
 				alert(xhttp.status + " Error!\n" + xhttp.responseText);
-				location.reload()
+				UpdatePage();
 			}
 		}
 	};
@@ -106,13 +224,15 @@ function upload() {
             if (xhttp.readyState == 4) {
                 if (xhttp.status == 200) {
 					alert("Upload successfull!")
-					document.reload();
+//                    document.reload();
+                    document.getElementById("reboot").disabled = false;
+                    document.getElementById("doUpdate").disabled = false;
                 } else if (xhttp.status == 0) {
                     alert("Server closed the connection abruptly!");
-                    location.reload()
+                    UpdatePage();
                 } else {
                     alert(xhttp.status + " Error!\n" + xhttp.responseText);
-                    location.reload()
+                    UpdatePage();
                 }
             }
         };
@@ -123,6 +243,79 @@ function upload() {
         xhttp.send(file);
     }
 }
+
+function uploadhtml() {
+	var xhttp = new XMLHttpRequest();
+	
+	/* first delete the old firmware */	
+	xhttp.onreadystatechange = function() {
+		if (xhttp.readyState == 4) {
+			if (xhttp.status == 200) {
+				/* keine Reaktion, damit sich das Dokument nicht ändert */
+			} else if (xhttp.status == 0) {
+				alert("Server closed the connection abruptly!");
+				UpdatePage();
+			} else {
+				alert(xhttp.status + " Error!\n" + xhttp.responseText);
+				UpdatePage();
+			}
+		}
+	};
+	xhttp.open("GET", "/ota?delete=html.zip", false);
+	xhttp.send();
+	/* ----------------------------- */
+	
+    var filePath = document.getElementById("filepathhtml").value;
+    var upload_path = "/upload/" + filePath;
+    var fileInput = document.getElementById("newfilehtml").files;
+
+    /* Max size of an individual file. Make sure this
+     * value is same as that set in file_server.c */
+    var MAX_FILE_SIZE = 2000*1024;
+    var MAX_FILE_SIZE_STR = "2000KB";
+
+    if (fileInput.length == 0) {
+        alert("No file selected!");
+    } else if (filePath.length == 0) {
+        alert("File path on server is not set!");
+    } else if (filePath.indexOf(' ') >= 0) {
+        alert("File path on server cannot have spaces!");
+    } else if (filePath[filePath.length-1] == '/') {
+        alert("File name not specified after path!");
+    } else if (fileInput[0].size > 2000*1024) {
+        alert("File size must be less than 2000KB!");
+    } else {
+        document.getElementById("newfilehtml").disabled = true;
+        document.getElementById("filepathhtml").disabled = true;
+        document.getElementById("uploadhtml").disabled = true;
+		
+        xhttp.onreadystatechange = function() {
+            if (xhttp.readyState == 4) {
+                if (xhttp.status == 200) {
+					alert("Upload successfull!")
+//                    document.reload();
+                    document.getElementById("reboot").disabled = false;
+                    document.getElementById("doUpdatehtml").disabled = false;
+                } else if (xhttp.status == 0) {
+                    alert("Server closed the connection abruptly!");
+                    UpdatePage();
+                } else {
+                    alert(xhttp.status + " Error!\n" + xhttp.responseText);
+                    UpdatePage();
+                }
+            }
+        };
+		
+
+        var file = fileInput[0];
+        xhttp.open("POST", upload_path, true);
+        xhttp.send(file);
+    }
+}
+
+
+init();
+
 </script>
 
 

+ 7 - 5
sd-card/html/upload_script.html

@@ -29,6 +29,8 @@
         </table>
     </td></tr>
 </table>
+
+<script type="text/javascript" src="./gethost.js"></script> 
 <script>
 function setpath() {
     var fileserverpraefix = "/fileserver";
@@ -68,13 +70,13 @@ function deleteall(){
 //                    document.open();
 //                    document.write(xhttp.responseText);
 //                    document.close();
-                    location.reload();
+                    UpdatePage();
                 } else if (xhttp.status == 0) {
                     alert("Server closed the connection abruptly!");
-                    location.reload();
+                    UpdatePage();
                 } else {
 //                    alert(xhttp.status + " Error!\n" + xhttp.responseText);
-                    location.reload();
+                    UpdatePage();
                 }
             }
         };
@@ -119,10 +121,10 @@ function upload() {
                     document.close();
                 } else if (xhttp.status == 0) {
                     alert("Server closed the connection abruptly!");
-                    location.reload()
+                    UpdatePage();
                 } else {
                     alert(xhttp.status + " Error!\n" + xhttp.responseText);
-                    location.reload()
+                    UpdatePage();
                 }
             }
         };

+ 2 - 4
sd-card/html/wasserzaehler_roi.html

@@ -71,8 +71,6 @@
 		}
 	</style>
 	<script type="text/javascript">
-		//<![CDATA[
-		//]]>
 
 	</script>
 </head>
@@ -85,11 +83,11 @@
 		<table>
 			<tr>
 				Raw Value:<p>
-				<iframe name="maincontent" id ="maincontent" src="/wasserzaehler.html?rawvalue=true" title="fileserver" allowfullscreen></iframe>
+				<iframe name="maincontent1" id ="maincontent1" src="/wasserzaehler.html?rawvalue=true" title="fileserver" allowfullscreen></iframe>
 			</tr>
 			<tr>
 				Corrected Value:<p>
-				<iframe name="maincontent" id ="maincontent" src="/wasserzaehler.html" title="fileserver" allowfullscreen></iframe>
+				<iframe name="maincontent2" id ="maincontent2" src="/wasserzaehler.html" title="fileserver" allowfullscreen></iframe>
 			</tr>
 		</table>
 	</td>