ota_page.html 15 KB

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