| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- <!DOCTYPE html>
- <html>
- <head>
- <link rel="icon" href="favicon.ico" type="image/x-icon">
- <title>OTA Update</title>
- <meta charset="utf-8">
- <script type="text/javascript" src="./gethost.js"></script>
- <style>
- h1 {font-size: 2em;}
- h2 {font-size: 1.5em;}
- h3 {font-size: 1.2em;}
- p {font-size: 1em;}
- input[type=number] {
- width: 138px;
- padding: 10px 5px;
- display: inline-block;
- border: 1px solid #ccc;
- font-size: 16px;
- }
- .button {
- padding: 10px 20px;
- width: 211px;
- font-size: 16px;
- }
- </style>
- </head>
- <body style="font-family: arial; padding: 0px 10px;">
- <p>Check the <a href="https://github.com/jomjol/AI-on-the-edge-device/releases" target=_blank>Release Page</a> to see if there is an update available.</p>
- <p>Normally, the overall update package (<i><span style="font-family:monospace">update__*.zip</span></i>) is your best choice!<br>
- Alternatively you can use the old style <i><span style="font-family:monospace">firmware__*.bin</span></i> and
- web interface (<i><span style="font-family:monospace">html__*.zip</span></i>). How ever it is strongly recommended to update firmware and
- web interface at the same time!</p>
- <hr>
- <h2>Update</h2>
- <b>Do not reload the page or switch to another page while the update is in progress!</b>
- <table class="fixed" border="0">
- <tr>
- <p>
- <label for="newfile">Select the file containig the update (
- <i><span style="font-family:monospace">update__*.zip</span></i>,
- <i><span style="font-family:monospace">firmware__*.bin</span></i>,
- <i><span style="font-family:monospace">html__*.zip</span></i>,
- <i><span style="font-family:monospace">*.tfl/tflite</span></i>)
- </p>
-
- </tr>
- <tr>
- <p>
- <input id="newfile" type="file" onchange="setpath()" style="width:100%;">
- </p>
- </tr>
- <tr>
- <p>
- <button class="button" style="width:300px" id="doUpdate" type="button" onclick="prepareOnServer()">Upload and update<br>(incl. reboot - if needed)</button>
- </p>
- </tr>
- <tr>
- <p>
- <h3><span id="status">Status: idle</span> <span id="progress"></span></h3>
- </p>
- </tr>
- </table>
- <script language="JavaScript">
- var basepath = "http://192.168.178.26";
- /* Max size of an individual file. Make sure this
- * value is same as that set in server_file.c */
- var MAX_FILE_SIZE = 8000*1024;
- var MAX_FILE_SIZE_STR = "8MB";
- var action_runtime = 0;
- var progressTimerHandle = null;
- function init(){
- basepath = getbasepath();
- document.getElementById("doUpdate").disabled = true;
- }
- function doRebootAfterUpdate() {
- if (confirm("Upload completed!\nThe device will reboot now and complete the update.\nThis will take up to 180s!")) {
- var stringota = "/reboot";
- window.location = stringota;
- window.location.href = stringota;
- window.location.assign(stringota);
- window.location.replace(stringota);
- }
- }
- function setpath() {
- var nameneu = document.getElementById("newfile").value;
- nameneu = nameneu.split(/[\\\/]/).pop();
- document.getElementById("doUpdate").disabled = false;
- document.getElementById("status").innerText = "Status: File selected";
- }
- function prepareOnServer() {
- var fileInput = document.getElementById("newfile").files;
- var nameneu = document.getElementById("newfile").value;
- filePath = nameneu.split(/[\\\/]/).pop();
- if (fileInput.length == 0) {
- alert("No file selected!");
- return;
- } else if (filePath.length == 0) {
- alert("File path on server is not set!");
- return;
- } else if (filePath.length > 100) {
- alert("Filename is to long! Max 100 characters.");
- return;
- } else if (filePath.indexOf(' ') >= 0) {
- alert("File path on server cannot have spaces!");
- return;
- } else if (filePath[filePath.length-1] == '/') {
- alert("File name not specified after path!");
- return;
- } else if (fileInput[0].size > MAX_FILE_SIZE) {
- alert("File size must be less than " + MAX_FILE_SIZE_STR + "!");
- return;
- }
- document.getElementById("status").innerText = "Status: Preparations on device";
- document.getElementById("doUpdate").disabled = true;
- var xhttp = new XMLHttpRequest();
- var nameneu = document.getElementById("newfile").value;
- filePath = nameneu.split(/[\\\/]/).pop();
- /* first delete the old firmware AND empty the /firmware directory*/
- xhttp.onreadystatechange = function() {
- if (xhttp.readyState == 4) {
- stopProgressTimer();
- if (xhttp.status == 200) {
- /* keine Reaktion, damit sich das Dokument nicht ändert */
- upload();
- } else if (xhttp.status == 0) {
- alert("Server closed the connection abruptly!");
- document.getElementById("doUpdate").disabled = false;
- } else {
- alert(xhttp.status + " Error!\n" + xhttp.responseText);
- document.getElementById("doUpdate").disabled = false;
- }
- }
- };
- startProgressTimer("Server preparations...");
- var _toDo = basepath + "/ota?task=emptyfirmwaredir";
- xhttp.open("GET", _toDo, true);
- xhttp.send();
- }
- function upload() {
- document.getElementById("newfile").disabled = true;
-
- var xhttp = new XMLHttpRequest();
- xhttp.onreadystatechange = function() {
- if (xhttp.readyState == 4) {
- stopProgressTimer();
- if (xhttp.status == 200) {
- // alert("Upload successfull!")
- // document.reload();
- extract();
- } else if (xhttp.status == 0) {
- alert("Server closed the connection abruptly!");
- document.getElementById("doUpdate").disabled = false;
- } else {
- alert(xhttp.status + " Error!\n" + xhttp.responseText);
- document.getElementById("doUpdate").disabled = false;
- }
- }
- };
-
- startProgressTimer("Upload");
- var fileInput = document.getElementById("newfile").files;
- var file = fileInput[0];
- var upload_path = "/upload/firmware/" + filePath;
- xhttp.open("POST", upload_path, true);
- document.getElementById("status").innerText = "Status: Uploading (takes up to 60s)...";
- xhttp.send(file);
- }
- function extract() {
- document.getElementById("status").innerText = "Status: Processing on device (takes up to 3 minutes)...";
- var xhttp = new XMLHttpRequest();
- /* first delete the old firmware */
- xhttp.onreadystatechange = function() {
- if (xhttp.readyState == 4) {
- stopProgressTimer();
- if (xhttp.status == 200) {
- document.getElementById("status").innerText = "Status: Update completed!";
- document.getElementById("doUpdate").disabled = true;
- document.getElementById("newfile").disabled = false;
- document.cookie = "page=overview.html"; // Make sure after the reboot we go to the overview page
- if (xhttp.responseText.startsWith("reboot"))
- {
- doRebootAfterUpdate();
- }
- else
- {
- alert("Processing done!\n\n" + xhttp.responseText);
- }
- } else if (xhttp.status == 0) {
- alert("Server closed the connection abruptly!");
- UpdatePage();
- } else {
- alert(xhttp.status + " Error!\n" + xhttp.responseText);
- UpdatePage();
- }
- }
- };
- startProgressTimer("Extraction");
- var nameneu = document.getElementById("newfile").value;
- filePath = nameneu.split(/[\\\/]/).pop();
- var _toDo = basepath + "/ota?task=update&file=" + filePath;
- xhttp.open("GET", _toDo, true);
- xhttp.send();
- }
- function startProgressTimer(step) {
- console.log(step + "...");
- document.getElementById('progress').innerHTML = "(0s)";
- action_runtime = 0;
- progressTimerHandle = setInterval(function() {
- action_runtime += 1;
- console.log("Progress: " + action_runtime + "s");
- document.getElementById('progress').innerHTML = "(" + action_runtime + "s)";
- }, 1000);
- }
- function stopProgressTimer() {
- clearInterval(progressTimerHandle);
- document.getElementById('progress').innerHTML = "";
- }
- init();
- </script>
- </body>
- </html>
|