ota_page.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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. <h3>It is strongly recommended to update firmware and content of /html directory on SD-card at the same time!</h3>
  28. <hr>
  29. <h2>1. Firmware Update</h2>
  30. <table class="fixed" border="0">
  31. <tr>
  32. <td>
  33. <table border="0">
  34. <tr>
  35. <td style="width: 230px">
  36. <label for="newfile">Select the firmware file:</label>
  37. </td>
  38. <td colspan="2">
  39. <input id="newfile" type="file" onchange="setpath()" style="width:100%;">
  40. </td>
  41. <td rowspan="2" style="padding-left:50px">
  42. <button class="button" id="doUpdate" type="button" onclick="doUpdate()">Flash the firmware<br>(Takes about 60s)</button>
  43. </td>
  44. </tr>
  45. <tr>
  46. <td>
  47. <label for="filepath">Set path on server:</label>
  48. </td>
  49. <td>
  50. <input id="filepath" type="text" style="width:100%;" readonly>
  51. </td>
  52. <td>
  53. <button id="upload" type="button" onclick="upload()">Upload</button>
  54. </td>
  55. </tr>
  56. </table>
  57. </td>
  58. </tr>
  59. </table>
  60. <hr>
  61. <h2>2. Update "/html" directory</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 zipped /html content:</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 "/html" directory</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%;" 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. <hr>
  93. <h2>3. Reboot</h2>
  94. <button class="button" id="reboot" type="button" onclick="doReboot()">Reboot to activate updates</button>
  95. <hr>
  96. <h2>4. Upload neural network definition (tfl/tflite file)</h2>
  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%;" 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. The file must be activated!
  124. Use the <a href="index_configure.html" target="_parent">Config Page</a> or do it manually in the config.ini file.
  125. </table>
  126. <script type="text/javascript" src="./gethost.js"></script>
  127. <script language="JavaScript">
  128. function init(){
  129. document.getElementById("reboot").disabled = true;
  130. document.getElementById("upload").disabled = true;
  131. document.getElementById("uploadhtml").disabled = true;
  132. document.getElementById("doUpdate").disabled = true;
  133. document.getElementById("doUpdatehtml").disabled = true;
  134. document.getElementById("uploadtfl").disabled = true;
  135. }
  136. function doUpdate() {
  137. if (confirm("Are you sure to update the firmware?")) {
  138. var stringota = "/ota?file=firmware.bin";
  139. document.getElementById("doUpdate").disabled = true;
  140. var xhttp = new XMLHttpRequest();
  141. xhttp.onreadystatechange = function() {
  142. if (xhttp.readyState == 4) {
  143. if (xhttp.status == 200) {
  144. document.getElementById("reboot").disabled = false;
  145. alert("Flash successfull - Reboot necessary to make changes active.");
  146. /* keine Reaktion, damit sich das Dokument nicht ändert */
  147. } else if (xhttp.status == 0) {
  148. alert("Server closed the connection abruptly!");
  149. UpdatePage();
  150. } else {
  151. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  152. UpdatePage();
  153. }
  154. }
  155. };
  156. xhttp.open("GET", stringota, true);
  157. xhttp.send();
  158. }
  159. }
  160. function doUpdatehtml() {
  161. if (confirm("Are you sure to update the /html content?")) {
  162. var stringota = "/ota?task=unziphtml";
  163. document.getElementById("doUpdatehtml").disabled = true;
  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. }
  198. function setpathhtml() {
  199. var fileserverpraefix = "/firmware/html.zip";
  200. document.getElementById("filepathhtml").value = fileserverpraefix;
  201. document.getElementById("uploadhtml").disabled = false;
  202. }
  203. function setpathtfl() {
  204. var nameneu = document.getElementById("newfiletfl").value;
  205. nameneu = nameneu.split(/[\\\/]/).pop();
  206. var fileserverpraefix = "/config/" + nameneu;
  207. document.getElementById("filepathtfl").value = fileserverpraefix;
  208. document.getElementById("uploadtfl").disabled = false;
  209. }
  210. function upload() {
  211. var xhttp = new XMLHttpRequest();
  212. /* first delete the old firmware */
  213. xhttp.onreadystatechange = function() {
  214. if (xhttp.readyState == 4) {
  215. if (xhttp.status == 200) {
  216. /* keine Reaktion, damit sich das Dokument nicht ändert */
  217. } else if (xhttp.status == 0) {
  218. alert("Server closed the connection abruptly!");
  219. UpdatePage();
  220. } else {
  221. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  222. UpdatePage();
  223. }
  224. }
  225. };
  226. xhttp.open("GET", "/ota?delete=firmware.bin", false);
  227. xhttp.send();
  228. /* ----------------------------- */
  229. var filePath = document.getElementById("filepath").value;
  230. var upload_path = "/upload/" + filePath;
  231. var fileInput = document.getElementById("newfile").files;
  232. /* Max size of an individual file. Make sure this
  233. * value is same as that set in file_server.c */
  234. var MAX_FILE_SIZE = 2000*1024;
  235. var MAX_FILE_SIZE_STR = "2000KB";
  236. if (fileInput.length == 0) {
  237. alert("No file selected!");
  238. } else if (filePath.length == 0) {
  239. alert("File path on server is not set!");
  240. } else if (filePath.indexOf(' ') >= 0) {
  241. alert("File path on server cannot have spaces!");
  242. } else if (filePath[filePath.length-1] == '/') {
  243. alert("File name not specified after path!");
  244. } else if (fileInput[0].size > 2000*1024) {
  245. alert("File size must be less than 2000KB!");
  246. } else {
  247. document.getElementById("newfile").disabled = true;
  248. document.getElementById("filepath").disabled = true;
  249. document.getElementById("upload").disabled = true;
  250. xhttp.onreadystatechange = function() {
  251. if (xhttp.readyState == 4) {
  252. if (xhttp.status == 200) {
  253. alert("Upload successfull!")
  254. // document.reload();
  255. document.getElementById("reboot").disabled = false;
  256. document.getElementById("doUpdate").disabled = false;
  257. } else if (xhttp.status == 0) {
  258. alert("Server closed the connection abruptly!");
  259. UpdatePage();
  260. } else {
  261. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  262. UpdatePage();
  263. }
  264. }
  265. };
  266. var file = fileInput[0];
  267. xhttp.open("POST", upload_path, true);
  268. xhttp.send(file);
  269. }
  270. }
  271. function uploadhtml() {
  272. var xhttp = new XMLHttpRequest();
  273. /* first delete the old firmware */
  274. xhttp.onreadystatechange = function() {
  275. if (xhttp.readyState == 4) {
  276. if (xhttp.status == 200) {
  277. /* keine Reaktion, damit sich das Dokument nicht ändert */
  278. } else if (xhttp.status == 0) {
  279. alert("Server closed the connection abruptly!");
  280. UpdatePage();
  281. } else {
  282. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  283. UpdatePage();
  284. }
  285. }
  286. };
  287. xhttp.open("GET", "/ota?delete=html.zip", false);
  288. xhttp.send();
  289. /* ----------------------------- */
  290. var filePath = document.getElementById("filepathhtml").value;
  291. var upload_path = "/upload/" + filePath;
  292. var fileInput = document.getElementById("newfilehtml").files;
  293. /* Max size of an individual file. Make sure this
  294. * value is same as that set in file_server.c */
  295. var MAX_FILE_SIZE = 2000*1024;
  296. var MAX_FILE_SIZE_STR = "2000KB";
  297. if (fileInput.length == 0) {
  298. alert("No file selected!");
  299. } else if (filePath.length == 0) {
  300. alert("File path on server is not set!");
  301. } else if (filePath.indexOf(' ') >= 0) {
  302. alert("File path on server cannot have spaces!");
  303. } else if (filePath[filePath.length-1] == '/') {
  304. alert("File name not specified after path!");
  305. } else if (fileInput[0].size > 2000*1024) {
  306. alert("File size must be less than 2000KB!");
  307. } else {
  308. document.getElementById("newfilehtml").disabled = true;
  309. document.getElementById("filepathhtml").disabled = true;
  310. document.getElementById("uploadhtml").disabled = true;
  311. xhttp.onreadystatechange = function() {
  312. if (xhttp.readyState == 4) {
  313. if (xhttp.status == 200) {
  314. alert("Upload successfull!")
  315. // document.reload();
  316. document.getElementById("reboot").disabled = false;
  317. document.getElementById("doUpdatehtml").disabled = false;
  318. } else if (xhttp.status == 0) {
  319. alert("Server closed the connection abruptly!");
  320. UpdatePage();
  321. } else {
  322. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  323. UpdatePage();
  324. }
  325. }
  326. };
  327. var file = fileInput[0];
  328. xhttp.open("POST", upload_path, true);
  329. xhttp.send(file);
  330. }
  331. }
  332. function uploadtfl() {
  333. var xhttp = new XMLHttpRequest();
  334. /* first delete the old firmware */
  335. xhttp.onreadystatechange = function() {
  336. if (xhttp.readyState == 4) {
  337. if (xhttp.status == 200) {
  338. /* keine Reaktion, damit sich das Dokument nicht ändert */
  339. } else if (xhttp.status == 0) {
  340. alert("Server closed the connection abruptly!");
  341. UpdatePage();
  342. } else {
  343. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  344. UpdatePage();
  345. }
  346. }
  347. };
  348. /* ----------------------------- */
  349. var filePath = document.getElementById("filepathtfl").value;
  350. var upload_path = "/upload/" + filePath;
  351. var fileInput = document.getElementById("newfiletfl").files;
  352. /* Max size of an individual file. Make sure this
  353. * value is same as that set in file_server.c */
  354. var MAX_FILE_SIZE = 2000*1024;
  355. var MAX_FILE_SIZE_STR = "2000KB";
  356. if (fileInput.length == 0) {
  357. alert("No file selected!");
  358. } else if (filePath.length == 0) {
  359. alert("File path on server is not set!");
  360. } else if (filePath.indexOf(' ') >= 0) {
  361. alert("File path on server cannot have spaces!");
  362. } else if (filePath[filePath.length-1] == '/') {
  363. alert("File name not specified after path!");
  364. } else if (fileInput[0].size > 2000*1024) {
  365. alert("File size must be less than 2000KB!");
  366. } else {
  367. document.getElementById("newfiletfl").disabled = true;
  368. document.getElementById("filepathtfl").disabled = true;
  369. document.getElementById("uploadtfl").disabled = true;
  370. xhttp.onreadystatechange = function() {
  371. if (xhttp.readyState == 4) {
  372. if (xhttp.status == 200) {
  373. alert("Upload successfull!")
  374. document.getElementById("newfiletfl").disabled = false;
  375. document.getElementById("filepathtfl").disabled = false;
  376. } else if (xhttp.status == 0) {
  377. alert("Server closed the connection abruptly!");
  378. UpdatePage();
  379. } else {
  380. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  381. UpdatePage();
  382. }
  383. }
  384. };
  385. var file = fileInput[0];
  386. xhttp.open("POST", upload_path, true);
  387. xhttp.send(file);
  388. }
  389. }
  390. init();
  391. </script>
  392. </body>
  393. </html>