ota_page.html 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <link rel="icon" href="favicon.ico" type="image/x-icon">
  5. <title>OTA Update</title>
  6. <meta charset="utf-8">
  7. <script type="text/javascript" src="./gethost.js"></script>
  8. <style>
  9. h1 {font-size: 2em;}
  10. h2 {font-size: 1.5em;}
  11. h3 {font-size: 1.2em;}
  12. p {font-size: 1em;}
  13. input[type=number] {
  14. width: 138px;
  15. padding: 10px 5px;
  16. display: inline-block;
  17. border: 1px solid #ccc;
  18. font-size: 16px;
  19. }
  20. .button {
  21. padding: 10px 20px;
  22. width: 211px;
  23. font-size: 16px;
  24. }
  25. </style>
  26. </head>
  27. <body style="font-family: arial; padding: 0px 10px;">
  28. <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>
  29. <p>Normally, the overall update package (<i><span style="font-family:monospace">update__*.zip</span></i>) is your best choice!<br>
  30. Alternatively you can use the old style <i><span style="font-family:monospace">firmware__*.bin</span></i> and
  31. web interface (<i><span style="font-family:monospace">html__*.zip</span></i>). How ever it is strongly recommended to update firmware and
  32. web interface at the same time!</p>
  33. <hr>
  34. <h2>Update</h2>
  35. <b>Do not reload the page or switch to another page while the update is in progress!</b>
  36. <table class="fixed" border="0">
  37. <tr>
  38. <p>
  39. <label for="newfile">Select the file containig the update (
  40. <i><span style="font-family:monospace">update__*.zip</span></i>,
  41. <i><span style="font-family:monospace">firmware__*.bin</span></i>,
  42. <i><span style="font-family:monospace">html__*.zip</span></i>,
  43. <i><span style="font-family:monospace">*.tfl/tflite</span></i>)
  44. </p>
  45. </tr>
  46. <tr>
  47. <p>
  48. <input id="newfile" type="file" onchange="setpath()" style="width:100%;">
  49. </p>
  50. </tr>
  51. <tr>
  52. <p>
  53. <button class="button" style="width:300px" id="doUpdate" type="button" onclick="prepareOnServer()">Upload and update<br>(incl. reboot - if needed)</button>
  54. </p>
  55. </tr>
  56. <tr>
  57. <p>
  58. <h3><span id="status">Status: idle</span> <span id="progress"></span></h3>
  59. </p>
  60. </tr>
  61. </table>
  62. <script language="JavaScript">
  63. var basepath = "http://192.168.178.26";
  64. /* Max size of an individual file. Make sure this
  65. * value is same as that set in server_file.c */
  66. var MAX_FILE_SIZE = 8000*1024;
  67. var MAX_FILE_SIZE_STR = "8MB";
  68. var action_runtime = 0;
  69. var progressTimerHandle = null;
  70. function init(){
  71. basepath = getbasepath();
  72. document.getElementById("doUpdate").disabled = true;
  73. }
  74. function doRebootAfterUpdate() {
  75. if (confirm("Upload completed!\nThe device will reboot now and complete the update.\nThis will take up to 180s!")) {
  76. var stringota = "/reboot";
  77. window.location = stringota;
  78. window.location.href = stringota;
  79. window.location.assign(stringota);
  80. window.location.replace(stringota);
  81. }
  82. }
  83. function setpath() {
  84. var nameneu = document.getElementById("newfile").value;
  85. nameneu = nameneu.split(/[\\\/]/).pop();
  86. document.getElementById("doUpdate").disabled = false;
  87. document.getElementById("status").innerText = "Status: File selected";
  88. }
  89. function prepareOnServer() {
  90. var fileInput = document.getElementById("newfile").files;
  91. var nameneu = document.getElementById("newfile").value;
  92. filePath = nameneu.split(/[\\\/]/).pop();
  93. if (fileInput.length == 0) {
  94. alert("No file selected!");
  95. return;
  96. } else if (filePath.length == 0) {
  97. alert("File path on server is not set!");
  98. return;
  99. } else if (filePath.length > 100) {
  100. alert("Filename is to long! Max 100 characters.");
  101. return;
  102. } else if (filePath.indexOf(' ') >= 0) {
  103. alert("File path on server cannot have spaces!");
  104. return;
  105. } else if (filePath[filePath.length-1] == '/') {
  106. alert("File name not specified after path!");
  107. return;
  108. } else if (fileInput[0].size > MAX_FILE_SIZE) {
  109. alert("File size must be less than " + MAX_FILE_SIZE_STR + "!");
  110. return;
  111. }
  112. document.getElementById("status").innerText = "Status: Preparations on device";
  113. document.getElementById("doUpdate").disabled = true;
  114. var xhttp = new XMLHttpRequest();
  115. var nameneu = document.getElementById("newfile").value;
  116. filePath = nameneu.split(/[\\\/]/).pop();
  117. /* first delete the old firmware AND empty the /firmware directory*/
  118. xhttp.onreadystatechange = function() {
  119. if (xhttp.readyState == 4) {
  120. stopProgressTimer();
  121. if (xhttp.status == 200) {
  122. /* keine Reaktion, damit sich das Dokument nicht ändert */
  123. upload();
  124. } else if (xhttp.status == 0) {
  125. alert("Server closed the connection abruptly!");
  126. document.getElementById("doUpdate").disabled = false;
  127. } else {
  128. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  129. document.getElementById("doUpdate").disabled = false;
  130. }
  131. }
  132. };
  133. startProgressTimer("Server preparations...");
  134. var _toDo = basepath + "/ota?task=emptyfirmwaredir";
  135. xhttp.open("GET", _toDo, true);
  136. xhttp.send();
  137. }
  138. function upload() {
  139. document.getElementById("newfile").disabled = true;
  140. var xhttp = new XMLHttpRequest();
  141. xhttp.onreadystatechange = function() {
  142. if (xhttp.readyState == 4) {
  143. stopProgressTimer();
  144. if (xhttp.status == 200) {
  145. // alert("Upload successfull!")
  146. // document.reload();
  147. extract();
  148. } else if (xhttp.status == 0) {
  149. alert("Server closed the connection abruptly!");
  150. document.getElementById("doUpdate").disabled = false;
  151. } else {
  152. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  153. document.getElementById("doUpdate").disabled = false;
  154. }
  155. }
  156. };
  157. startProgressTimer("Upload");
  158. var fileInput = document.getElementById("newfile").files;
  159. var file = fileInput[0];
  160. var upload_path = "/upload/firmware/" + filePath;
  161. xhttp.open("POST", upload_path, true);
  162. document.getElementById("status").innerText = "Status: Uploading (takes up to 60s)...";
  163. xhttp.send(file);
  164. }
  165. function extract() {
  166. document.getElementById("status").innerText = "Status: Processing on device (takes up to 3 minutes)...";
  167. var xhttp = new XMLHttpRequest();
  168. /* first delete the old firmware */
  169. xhttp.onreadystatechange = function() {
  170. if (xhttp.readyState == 4) {
  171. stopProgressTimer();
  172. if (xhttp.status == 200) {
  173. document.getElementById("status").innerText = "Status: Update completed!";
  174. document.getElementById("doUpdate").disabled = true;
  175. document.getElementById("newfile").disabled = false;
  176. document.cookie = "page=overview.html"; // Make sure after the reboot we go to the overview page
  177. if (xhttp.responseText.startsWith("reboot"))
  178. {
  179. doRebootAfterUpdate();
  180. }
  181. else
  182. {
  183. alert("Processing done!\n\n" + xhttp.responseText);
  184. }
  185. } else if (xhttp.status == 0) {
  186. alert("Server closed the connection abruptly!");
  187. UpdatePage();
  188. } else {
  189. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  190. UpdatePage();
  191. }
  192. }
  193. };
  194. startProgressTimer("Extraction");
  195. var nameneu = document.getElementById("newfile").value;
  196. filePath = nameneu.split(/[\\\/]/).pop();
  197. var _toDo = basepath + "/ota?task=update&file=" + filePath;
  198. xhttp.open("GET", _toDo, true);
  199. xhttp.send();
  200. }
  201. function startProgressTimer(step) {
  202. console.log(step + "...");
  203. document.getElementById('progress').innerHTML = "(0s)";
  204. action_runtime = 0;
  205. progressTimerHandle = setInterval(function() {
  206. action_runtime += 1;
  207. console.log("Progress: " + action_runtime + "s");
  208. document.getElementById('progress').innerHTML = "(" + action_runtime + "s)";
  209. }, 1000);
  210. }
  211. function stopProgressTimer() {
  212. clearInterval(progressTimerHandle);
  213. document.getElementById('progress').innerHTML = "";
  214. }
  215. init();
  216. </script>
  217. </body>
  218. </html>