ota_page_v2.html 14 KB

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