ota_page.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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. document.getElementById("doUpdate").disabled = true;
  154. var xhttp = new XMLHttpRequest();
  155. xhttp.onreadystatechange = function() {
  156. if (xhttp.readyState == 4) {
  157. if (xhttp.status == 200) {
  158. document.getElementById("reboot").disabled = false;
  159. alert("Flash successfull - Reboot necessary to make changes active.");
  160. /* keine Reaktion, damit sich das Dokument nicht ändert */
  161. } else if (xhttp.status == 0) {
  162. alert("Server closed the connection abruptly!");
  163. UpdatePage();
  164. } else {
  165. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  166. UpdatePage();
  167. }
  168. }
  169. };
  170. xhttp.open("GET", stringota, true);
  171. xhttp.send();
  172. }
  173. }
  174. function doUpdatehtml() {
  175. if (confirm("Are you sure to update the /html content?")) {
  176. var stringota = "/ota?task=unziphtml";
  177. document.getElementById("doUpdatehtml").disabled = true;
  178. var xhttp = new XMLHttpRequest();
  179. xhttp.onreadystatechange = function() {
  180. if (xhttp.readyState == 4) {
  181. if (xhttp.status == 200) {
  182. document.getElementById("reboot").disabled = false;
  183. alert("Update /html successful!");
  184. /* keine Reaktion, damit sich das Dokument nicht ändert */
  185. } else if (xhttp.status == 0) {
  186. alert("Server closed the connection abruptly!");
  187. UpdatePage();
  188. } else {
  189. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  190. UpdatePage();
  191. }
  192. }
  193. };
  194. xhttp.open("GET", stringota, true);
  195. xhttp.send();
  196. }
  197. }
  198. function doReboot() {
  199. if (confirm("Are you sure you want to reboot the ESP32?")) {
  200. var stringota = "/reboot";
  201. window.location = stringota;
  202. window.location.href = stringota;
  203. window.location.assign(stringota);
  204. window.location.replace(stringota);
  205. }
  206. }
  207. function setpath() {
  208. var fileserverpraefix = "/firmware/firmware.bin";
  209. document.getElementById("filepath").value = fileserverpraefix;
  210. document.getElementById("upload").disabled = false;
  211. }
  212. function setpathhtml() {
  213. var fileserverpraefix = "/firmware/html.zip";
  214. document.getElementById("filepathhtml").value = fileserverpraefix;
  215. document.getElementById("uploadhtml").disabled = false;
  216. }
  217. function setpathtfl() {
  218. var nameneu = document.getElementById("newfiletfl").value;
  219. nameneu = nameneu.split(/[\\\/]/).pop();
  220. var fileserverpraefix = "/config/" + nameneu;
  221. document.getElementById("filepathtfl").value = fileserverpraefix;
  222. document.getElementById("uploadtfl").disabled = false;
  223. }
  224. function upload() {
  225. var xhttp = new XMLHttpRequest();
  226. /* first delete the old firmware */
  227. xhttp.onreadystatechange = function() {
  228. if (xhttp.readyState == 4) {
  229. if (xhttp.status == 200) {
  230. /* keine Reaktion, damit sich das Dokument nicht ändert */
  231. } else if (xhttp.status == 0) {
  232. alert("Server closed the connection abruptly!");
  233. UpdatePage();
  234. } else {
  235. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  236. UpdatePage();
  237. }
  238. }
  239. };
  240. xhttp.open("GET", "/ota?delete=firmware.bin", false);
  241. xhttp.send();
  242. /* ----------------------------- */
  243. var filePath = document.getElementById("filepath").value;
  244. var upload_path = "/upload/" + filePath;
  245. var fileInput = document.getElementById("newfile").files;
  246. /* Max size of an individual file. Make sure this
  247. * value is same as that set in file_server.c */
  248. var MAX_FILE_SIZE = 2000*1024;
  249. var MAX_FILE_SIZE_STR = "2000KB";
  250. if (fileInput.length == 0) {
  251. alert("No file selected!");
  252. } else if (filePath.length == 0) {
  253. alert("File path on server is not set!");
  254. } else if (filePath.indexOf(' ') >= 0) {
  255. alert("File path on server cannot have spaces!");
  256. } else if (filePath[filePath.length-1] == '/') {
  257. alert("File name not specified after path!");
  258. } else if (fileInput[0].size > 2000*1024) {
  259. alert("File size must be less than 2000KB!");
  260. } else {
  261. document.getElementById("newfile").disabled = true;
  262. document.getElementById("filepath").disabled = true;
  263. document.getElementById("upload").disabled = true;
  264. xhttp.onreadystatechange = function() {
  265. if (xhttp.readyState == 4) {
  266. if (xhttp.status == 200) {
  267. alert("Upload successfull!")
  268. // document.reload();
  269. document.getElementById("reboot").disabled = false;
  270. document.getElementById("doUpdate").disabled = false;
  271. } else if (xhttp.status == 0) {
  272. alert("Server closed the connection abruptly!");
  273. UpdatePage();
  274. } else {
  275. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  276. UpdatePage();
  277. }
  278. }
  279. };
  280. var file = fileInput[0];
  281. xhttp.open("POST", upload_path, true);
  282. xhttp.send(file);
  283. }
  284. }
  285. function uploadhtml() {
  286. var xhttp = new XMLHttpRequest();
  287. /* first delete the old firmware */
  288. xhttp.onreadystatechange = function() {
  289. if (xhttp.readyState == 4) {
  290. if (xhttp.status == 200) {
  291. /* keine Reaktion, damit sich das Dokument nicht ändert */
  292. } else if (xhttp.status == 0) {
  293. alert("Server closed the connection abruptly!");
  294. UpdatePage();
  295. } else {
  296. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  297. UpdatePage();
  298. }
  299. }
  300. };
  301. xhttp.open("GET", "/ota?delete=html.zip", false);
  302. xhttp.send();
  303. /* ----------------------------- */
  304. var filePath = document.getElementById("filepathhtml").value;
  305. var upload_path = "/upload/" + filePath;
  306. var fileInput = document.getElementById("newfilehtml").files;
  307. /* Max size of an individual file. Make sure this
  308. * value is same as that set in file_server.c */
  309. var MAX_FILE_SIZE = 2000*1024;
  310. var MAX_FILE_SIZE_STR = "2000KB";
  311. if (fileInput.length == 0) {
  312. alert("No file selected!");
  313. } else if (filePath.length == 0) {
  314. alert("File path on server is not set!");
  315. } else if (filePath.indexOf(' ') >= 0) {
  316. alert("File path on server cannot have spaces!");
  317. } else if (filePath[filePath.length-1] == '/') {
  318. alert("File name not specified after path!");
  319. } else if (fileInput[0].size > 2000*1024) {
  320. alert("File size must be less than 2000KB!");
  321. } else {
  322. document.getElementById("newfilehtml").disabled = true;
  323. document.getElementById("filepathhtml").disabled = true;
  324. document.getElementById("uploadhtml").disabled = true;
  325. xhttp.onreadystatechange = function() {
  326. if (xhttp.readyState == 4) {
  327. if (xhttp.status == 200) {
  328. alert("Upload successfull!")
  329. // document.reload();
  330. document.getElementById("reboot").disabled = false;
  331. document.getElementById("doUpdatehtml").disabled = false;
  332. } else if (xhttp.status == 0) {
  333. alert("Server closed the connection abruptly!");
  334. UpdatePage();
  335. } else {
  336. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  337. UpdatePage();
  338. }
  339. }
  340. };
  341. var file = fileInput[0];
  342. xhttp.open("POST", upload_path, true);
  343. xhttp.send(file);
  344. }
  345. }
  346. function uploadtfl() {
  347. var xhttp = new XMLHttpRequest();
  348. /* first delete the old firmware */
  349. xhttp.onreadystatechange = function() {
  350. if (xhttp.readyState == 4) {
  351. if (xhttp.status == 200) {
  352. /* keine Reaktion, damit sich das Dokument nicht ändert */
  353. } else if (xhttp.status == 0) {
  354. alert("Server closed the connection abruptly!");
  355. UpdatePage();
  356. } else {
  357. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  358. UpdatePage();
  359. }
  360. }
  361. };
  362. /* ----------------------------- */
  363. var filePath = document.getElementById("filepathtfl").value;
  364. var upload_path = "/upload/" + filePath;
  365. var fileInput = document.getElementById("newfiletfl").files;
  366. /* Max size of an individual file. Make sure this
  367. * value is same as that set in file_server.c */
  368. var MAX_FILE_SIZE = 2000*1024;
  369. var MAX_FILE_SIZE_STR = "2000KB";
  370. if (fileInput.length == 0) {
  371. alert("No file selected!");
  372. } else if (filePath.length == 0) {
  373. alert("File path on server is not set!");
  374. } else if (filePath.indexOf(' ') >= 0) {
  375. alert("File path on server cannot have spaces!");
  376. } else if (filePath[filePath.length-1] == '/') {
  377. alert("File name not specified after path!");
  378. } else if (fileInput[0].size > 2000*1024) {
  379. alert("File size must be less than 2000KB!");
  380. } else {
  381. document.getElementById("newfiletfl").disabled = true;
  382. document.getElementById("filepathtfl").disabled = true;
  383. document.getElementById("uploadtfl").disabled = true;
  384. xhttp.onreadystatechange = function() {
  385. if (xhttp.readyState == 4) {
  386. if (xhttp.status == 200) {
  387. alert("Upload successfull!")
  388. document.getElementById("newfiletfl").disabled = false;
  389. document.getElementById("filepathtfl").disabled = false;
  390. } else if (xhttp.status == 0) {
  391. alert("Server closed the connection abruptly!");
  392. UpdatePage();
  393. } else {
  394. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  395. UpdatePage();
  396. }
  397. }
  398. };
  399. var file = fileInput[0];
  400. xhttp.open("POST", upload_path, true);
  401. xhttp.send(file);
  402. }
  403. }
  404. init();
  405. </script>
  406. </body>
  407. </html>