ota_page_v2.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <html>
  2. <head>
  3. <link rel="icon" href="data:,">
  4. <title>jomjol - 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. <script type="text/javascript" src="./gethost.js"></script>
  90. <script language="JavaScript">
  91. function testupdownload(){
  92. var xhr = new XMLHttpRequest();
  93. xhr.open("get", "https://github.com/jomjol/AI-on-the-edge-device/raw/master/firmware/html.zip", true);
  94. xhr.onload = function () {
  95. xhr.close();
  96. var xhr2 = new XMLHttpRequest();
  97. xhr2.open("post", "/upload/firmware/html2.zip", true);
  98. xhr2.send(xhr.response);
  99. }
  100. xhr.send();
  101. }
  102. function init(){
  103. document.getElementById("reboot").disabled = true;
  104. document.getElementById("upload").disabled = true;
  105. document.getElementById("uploadhtml").disabled = true;
  106. document.getElementById("doUpdate").disabled = true;
  107. document.getElementById("doUpdatehtml").disabled = true;
  108. }
  109. function doUpdate() {
  110. if (confirm("Are you sure to update the firmware?")) {
  111. var stringota = "/ota?file=firmware.bin";
  112. var xhttp = new XMLHttpRequest();
  113. xhttp.onreadystatechange = function() {
  114. if (xhttp.readyState == 4) {
  115. if (xhttp.status == 200) {
  116. document.getElementById("reboot").disabled = false;
  117. alert("Flash successfull - Reboot necessary to make changes active.");
  118. /* keine Reaktion, damit sich das Dokument nicht ändert */
  119. } else if (xhttp.status == 0) {
  120. alert("Server closed the connection abruptly!");
  121. UpdatePage();
  122. } else {
  123. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  124. UpdatePage();
  125. }
  126. }
  127. };
  128. xhttp.open("GET", stringota, true);
  129. xhttp.send();
  130. }
  131. }
  132. function doUpdatehtml() {
  133. if (confirm("Are you sure to update the /html content?")) {
  134. var stringota = "/ota?task=unziphtml";
  135. var xhttp = new XMLHttpRequest();
  136. xhttp.onreadystatechange = function() {
  137. if (xhttp.readyState == 4) {
  138. if (xhttp.status == 200) {
  139. document.getElementById("reboot").disabled = false;
  140. alert("Update /html successful!");
  141. /* keine Reaktion, damit sich das Dokument nicht ändert */
  142. } else if (xhttp.status == 0) {
  143. alert("Server closed the connection abruptly!");
  144. UpdatePage();
  145. } else {
  146. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  147. UpdatePage();
  148. }
  149. }
  150. };
  151. xhttp.open("GET", stringota, true);
  152. xhttp.send();
  153. }
  154. }
  155. function doReboot() {
  156. if (confirm("Are you sure you want to reboot the ESP32?")) {
  157. var stringota = "/reboot";
  158. window.location = stringota;
  159. window.location.href = stringota;
  160. window.location.assign(stringota);
  161. window.location.replace(stringota);
  162. }
  163. }
  164. function setpath() {
  165. var fileserverpraefix = "/firmware/firmware.bin";
  166. document.getElementById("filepath").value = fileserverpraefix;
  167. document.getElementById("upload").disabled = false;
  168. }
  169. function setpathhtml() {
  170. var fileserverpraefix = "/firmware/html.zip";
  171. document.getElementById("filepathhtml").value = fileserverpraefix;
  172. document.getElementById("uploadhtml").disabled = false;
  173. }
  174. function upload() {
  175. var xhttp = new XMLHttpRequest();
  176. /* first delete the old firmware */
  177. xhttp.onreadystatechange = function() {
  178. if (xhttp.readyState == 4) {
  179. if (xhttp.status == 200) {
  180. /* keine Reaktion, damit sich das Dokument nicht ändert */
  181. } else if (xhttp.status == 0) {
  182. alert("Server closed the connection abruptly!");
  183. UpdatePage();
  184. } else {
  185. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  186. UpdatePage();
  187. }
  188. }
  189. };
  190. xhttp.open("GET", "/ota?delete=firmware.bin", false);
  191. xhttp.send();
  192. /* ----------------------------- */
  193. var filePath = document.getElementById("filepath").value;
  194. var upload_path = "/upload/" + filePath;
  195. var fileInput = document.getElementById("newfile").files;
  196. /* Max size of an individual file. Make sure this
  197. * value is same as that set in file_server.c */
  198. var MAX_FILE_SIZE = 2000*1024;
  199. var MAX_FILE_SIZE_STR = "2000KB";
  200. if (fileInput.length == 0) {
  201. alert("No file selected!");
  202. } else if (filePath.length == 0) {
  203. alert("File path on server is not set!");
  204. } else if (filePath.indexOf(' ') >= 0) {
  205. alert("File path on server cannot have spaces!");
  206. } else if (filePath[filePath.length-1] == '/') {
  207. alert("File name not specified after path!");
  208. } else if (fileInput[0].size > 2000*1024) {
  209. alert("File size must be less than 2000KB!");
  210. } else {
  211. document.getElementById("newfile").disabled = true;
  212. document.getElementById("filepath").disabled = true;
  213. document.getElementById("upload").disabled = true;
  214. xhttp.onreadystatechange = function() {
  215. if (xhttp.readyState == 4) {
  216. if (xhttp.status == 200) {
  217. alert("Upload successfull!")
  218. // document.reload();
  219. document.getElementById("reboot").disabled = false;
  220. document.getElementById("doUpdate").disabled = false;
  221. } else if (xhttp.status == 0) {
  222. alert("Server closed the connection abruptly!");
  223. UpdatePage();
  224. } else {
  225. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  226. UpdatePage();
  227. }
  228. }
  229. };
  230. var file = fileInput[0];
  231. xhttp.open("POST", upload_path, true);
  232. xhttp.send(file);
  233. }
  234. }
  235. function uploadhtml() {
  236. var xhttp = new XMLHttpRequest();
  237. /* first delete the old firmware */
  238. xhttp.onreadystatechange = function() {
  239. if (xhttp.readyState == 4) {
  240. if (xhttp.status == 200) {
  241. /* keine Reaktion, damit sich das Dokument nicht ändert */
  242. } else if (xhttp.status == 0) {
  243. alert("Server closed the connection abruptly!");
  244. UpdatePage();
  245. } else {
  246. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  247. UpdatePage();
  248. }
  249. }
  250. };
  251. xhttp.open("GET", "/ota?delete=html.zip", false);
  252. xhttp.send();
  253. /* ----------------------------- */
  254. var filePath = document.getElementById("filepathhtml").value;
  255. var upload_path = "/upload/" + filePath;
  256. var fileInput = document.getElementById("newfilehtml").files;
  257. /* Max size of an individual file. Make sure this
  258. * value is same as that set in file_server.c */
  259. var MAX_FILE_SIZE = 2000*1024;
  260. var MAX_FILE_SIZE_STR = "2000KB";
  261. if (fileInput.length == 0) {
  262. alert("No file selected!");
  263. } else if (filePath.length == 0) {
  264. alert("File path on server is not set!");
  265. } else if (filePath.indexOf(' ') >= 0) {
  266. alert("File path on server cannot have spaces!");
  267. } else if (filePath[filePath.length-1] == '/') {
  268. alert("File name not specified after path!");
  269. } else if (fileInput[0].size > 2000*1024) {
  270. alert("File size must be less than 2000KB!");
  271. } else {
  272. document.getElementById("newfilehtml").disabled = true;
  273. document.getElementById("filepathhtml").disabled = true;
  274. document.getElementById("uploadhtml").disabled = true;
  275. xhttp.onreadystatechange = function() {
  276. if (xhttp.readyState == 4) {
  277. if (xhttp.status == 200) {
  278. alert("Upload successfull!")
  279. // document.reload();
  280. document.getElementById("reboot").disabled = false;
  281. document.getElementById("doUpdatehtml").disabled = false;
  282. } else if (xhttp.status == 0) {
  283. alert("Server closed the connection abruptly!");
  284. UpdatePage();
  285. } else {
  286. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  287. UpdatePage();
  288. }
  289. }
  290. };
  291. var file = fileInput[0];
  292. xhttp.open("POST", upload_path, true);
  293. xhttp.send(file);
  294. }
  295. }
  296. init();
  297. </script>
  298. </body></html>