ota_page.html 7.4 KB

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