ota_page.html 15 KB

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