ota_page_new.html 7.0 KB

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