ota_page.html 11 KB

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