ota_page_v2.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <html><head>
  2. <title>jomjol - AI on the edge</title>
  3. <meta charset="utf-8">
  4. <meta name="viewport" content="width=device-width, initial-scale=1">
  5. <script type="text/javascript">
  6. //<![CDATA[
  7. //]]>
  8. </script>
  9. </head>
  10. <body>
  11. <button id="testupdownload" type="button" onclick="testupdownload()">UpDownload</button>
  12. <h3>It is strongly recommended to update firmware and content of /html directory on SD-card at the same time!</h3>
  13. <h2>1. Firmware Update</h2>
  14. <table class="fixed" border="0">
  15. <tr>
  16. <td>
  17. <table border="0">
  18. <tr>
  19. <td>
  20. <label for="newfile">Select the firmware file</label>
  21. </td>
  22. <td colspan="2">
  23. <input id="newfile" type="file" onchange="setpath()" style="width:100%;">
  24. </td>
  25. </tr>
  26. <tr>
  27. <td>
  28. <label for="filepath">Set path on server</label>
  29. </td>
  30. <td>
  31. <input id="filepath" type="text" style="width:100%;" readonly>
  32. </td>
  33. <td>
  34. <button id="upload" type="button" onclick="upload()">Upload</button>
  35. </td>
  36. </tr>
  37. </table>
  38. </td>
  39. </tr>
  40. <tr>
  41. <td>
  42. <button id="doUpdate" type="button" onclick="doUpdate()">Flash the firmware</button> (Takes about 60s)
  43. </td>
  44. </tr>
  45. </table>
  46. <h2>2. Update /html directory</h2>
  47. <table class="fixed" border="0">
  48. <tr>
  49. <td>
  50. <table border="0">
  51. <tr>
  52. <td>
  53. <label for="newfilehtml">Select the zipped /html content</label>
  54. </td>
  55. <td colspan="2">
  56. <input id="newfilehtml" type="file" onchange="setpathhtml()" style="width:100%;">
  57. </td>
  58. </tr>
  59. <tr>
  60. <td>
  61. <label for="filepathhtml">Set path on server</label>
  62. </td>
  63. <td>
  64. <input id="filepathhtml" type="text" style="width:100%;" readonly>
  65. </td>
  66. <td>
  67. <button id="uploadhtml" type="button" onclick="uploadhtml()">Upload</button>
  68. </td>
  69. </tr>
  70. </table>
  71. </td>
  72. </tr>
  73. <tr>
  74. <td>
  75. <button id="doUpdatehtml" type="button" onclick="doUpdatehtml()">Update "/html" directory</button>
  76. </td>
  77. </tr>
  78. </table>
  79. <h2>3. Reboot</h2>
  80. <table class="fixed" border="0">
  81. <tr>
  82. <td>
  83. <button id="reboot" type="button" onclick="doReboot()">Reboot to activate updates</button>
  84. </td>
  85. </tr>
  86. </table>
  87. <script type="text/javascript" src="./gethost.js"></script>
  88. <script language="JavaScript">
  89. function testupdownload(){
  90. var xhr = new XMLHttpRequest();
  91. xhr.open("get", "https://github.com/jomjol/AI-on-the-edge-device/raw/master/firmware/html.zip", true);
  92. xhr.onload = function () {
  93. xhr.close();
  94. var xhr2 = new XMLHttpRequest();
  95. xhr2.open("post", "/upload/firmware/html2.zip", true);
  96. xhr2.send(xhr.response);
  97. }
  98. xhr.send();
  99. }
  100. function init(){
  101. document.getElementById("reboot").disabled = true;
  102. document.getElementById("upload").disabled = true;
  103. document.getElementById("uploadhtml").disabled = true;
  104. document.getElementById("doUpdate").disabled = true;
  105. document.getElementById("doUpdatehtml").disabled = true;
  106. }
  107. function doUpdate() {
  108. if (confirm("Are you sure to update the firmware?")) {
  109. var stringota = "/ota?file=firmware.bin";
  110. var xhttp = new XMLHttpRequest();
  111. xhttp.onreadystatechange = function() {
  112. if (xhttp.readyState == 4) {
  113. if (xhttp.status == 200) {
  114. document.getElementById("reboot").disabled = false;
  115. alert("Flash successfull - Reboot necessary to make changes active.");
  116. /* keine Reaktion, damit sich das Dokument nicht ändert */
  117. } else if (xhttp.status == 0) {
  118. alert("Server closed the connection abruptly!");
  119. UpdatePage();
  120. } else {
  121. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  122. UpdatePage();
  123. }
  124. }
  125. };
  126. xhttp.open("GET", stringota, true);
  127. xhttp.send();
  128. }
  129. }
  130. function doUpdatehtml() {
  131. if (confirm("Are you sure to update the /html content?")) {
  132. var stringota = "/ota?task=unziphtml";
  133. var xhttp = new XMLHttpRequest();
  134. xhttp.onreadystatechange = function() {
  135. if (xhttp.readyState == 4) {
  136. if (xhttp.status == 200) {
  137. document.getElementById("reboot").disabled = false;
  138. alert("Update /html successful!");
  139. /* keine Reaktion, damit sich das Dokument nicht ändert */
  140. } else if (xhttp.status == 0) {
  141. alert("Server closed the connection abruptly!");
  142. UpdatePage();
  143. } else {
  144. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  145. UpdatePage();
  146. }
  147. }
  148. };
  149. xhttp.open("GET", stringota, true);
  150. xhttp.send();
  151. }
  152. }
  153. function doReboot() {
  154. if (confirm("Are you sure you want to reboot the ESP32?")) {
  155. var stringota = "/reboot";
  156. window.location = stringota;
  157. window.location.href = stringota;
  158. window.location.assign(stringota);
  159. window.location.replace(stringota);
  160. }
  161. }
  162. function setpath() {
  163. var fileserverpraefix = "/firmware/firmware.bin";
  164. document.getElementById("filepath").value = fileserverpraefix;
  165. document.getElementById("upload").disabled = false;
  166. }
  167. function setpathhtml() {
  168. var fileserverpraefix = "/firmware/html.zip";
  169. document.getElementById("filepathhtml").value = fileserverpraefix;
  170. document.getElementById("uploadhtml").disabled = false;
  171. }
  172. function upload() {
  173. var xhttp = new XMLHttpRequest();
  174. /* first delete the old firmware */
  175. xhttp.onreadystatechange = function() {
  176. if (xhttp.readyState == 4) {
  177. if (xhttp.status == 200) {
  178. /* keine Reaktion, damit sich das Dokument nicht ändert */
  179. } else if (xhttp.status == 0) {
  180. alert("Server closed the connection abruptly!");
  181. UpdatePage();
  182. } else {
  183. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  184. UpdatePage();
  185. }
  186. }
  187. };
  188. xhttp.open("GET", "/ota?delete=firmware.bin", false);
  189. xhttp.send();
  190. /* ----------------------------- */
  191. var filePath = document.getElementById("filepath").value;
  192. var upload_path = "/upload/" + filePath;
  193. var fileInput = document.getElementById("newfile").files;
  194. /* Max size of an individual file. Make sure this
  195. * value is same as that set in file_server.c */
  196. var MAX_FILE_SIZE = 2000*1024;
  197. var MAX_FILE_SIZE_STR = "2000KB";
  198. if (fileInput.length == 0) {
  199. alert("No file selected!");
  200. } else if (filePath.length == 0) {
  201. alert("File path on server is not set!");
  202. } else if (filePath.indexOf(' ') >= 0) {
  203. alert("File path on server cannot have spaces!");
  204. } else if (filePath[filePath.length-1] == '/') {
  205. alert("File name not specified after path!");
  206. } else if (fileInput[0].size > 2000*1024) {
  207. alert("File size must be less than 2000KB!");
  208. } else {
  209. document.getElementById("newfile").disabled = true;
  210. document.getElementById("filepath").disabled = true;
  211. document.getElementById("upload").disabled = true;
  212. xhttp.onreadystatechange = function() {
  213. if (xhttp.readyState == 4) {
  214. if (xhttp.status == 200) {
  215. alert("Upload successfull!")
  216. // document.reload();
  217. document.getElementById("reboot").disabled = false;
  218. document.getElementById("doUpdate").disabled = false;
  219. } else if (xhttp.status == 0) {
  220. alert("Server closed the connection abruptly!");
  221. UpdatePage();
  222. } else {
  223. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  224. UpdatePage();
  225. }
  226. }
  227. };
  228. var file = fileInput[0];
  229. xhttp.open("POST", upload_path, true);
  230. xhttp.send(file);
  231. }
  232. }
  233. function uploadhtml() {
  234. var xhttp = new XMLHttpRequest();
  235. /* first delete the old firmware */
  236. xhttp.onreadystatechange = function() {
  237. if (xhttp.readyState == 4) {
  238. if (xhttp.status == 200) {
  239. /* keine Reaktion, damit sich das Dokument nicht ändert */
  240. } else if (xhttp.status == 0) {
  241. alert("Server closed the connection abruptly!");
  242. UpdatePage();
  243. } else {
  244. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  245. UpdatePage();
  246. }
  247. }
  248. };
  249. xhttp.open("GET", "/ota?delete=html.zip", false);
  250. xhttp.send();
  251. /* ----------------------------- */
  252. var filePath = document.getElementById("filepathhtml").value;
  253. var upload_path = "/upload/" + filePath;
  254. var fileInput = document.getElementById("newfilehtml").files;
  255. /* Max size of an individual file. Make sure this
  256. * value is same as that set in file_server.c */
  257. var MAX_FILE_SIZE = 2000*1024;
  258. var MAX_FILE_SIZE_STR = "2000KB";
  259. if (fileInput.length == 0) {
  260. alert("No file selected!");
  261. } else if (filePath.length == 0) {
  262. alert("File path on server is not set!");
  263. } else if (filePath.indexOf(' ') >= 0) {
  264. alert("File path on server cannot have spaces!");
  265. } else if (filePath[filePath.length-1] == '/') {
  266. alert("File name not specified after path!");
  267. } else if (fileInput[0].size > 2000*1024) {
  268. alert("File size must be less than 2000KB!");
  269. } else {
  270. document.getElementById("newfilehtml").disabled = true;
  271. document.getElementById("filepathhtml").disabled = true;
  272. document.getElementById("uploadhtml").disabled = true;
  273. xhttp.onreadystatechange = function() {
  274. if (xhttp.readyState == 4) {
  275. if (xhttp.status == 200) {
  276. alert("Upload successfull!")
  277. // document.reload();
  278. document.getElementById("reboot").disabled = false;
  279. document.getElementById("doUpdatehtml").disabled = false;
  280. } else if (xhttp.status == 0) {
  281. alert("Server closed the connection abruptly!");
  282. UpdatePage();
  283. } else {
  284. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  285. UpdatePage();
  286. }
  287. }
  288. };
  289. var file = fileInput[0];
  290. xhttp.open("POST", upload_path, true);
  291. xhttp.send(file);
  292. }
  293. }
  294. init();
  295. </script>
  296. </body></html>