ota_page.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>OTA Update</title>
  5. <meta charset="utf-8">
  6. <style>
  7. h1 {font-size: 2em;}
  8. h2 {font-size: 1.5em;}
  9. h3 {font-size: 1.2em;}
  10. p {font-size: 1em;}
  11. input[type=number] {
  12. width: 138px;
  13. padding: 10px 5px;
  14. display: inline-block;
  15. border: 1px solid #ccc;
  16. font-size: 16px;
  17. }
  18. .button {
  19. padding: 10px 20px;
  20. width: 211px;
  21. font-size: 16px;
  22. }
  23. </style>
  24. </head>
  25. <body style="font-family: arial; padding: 0px 10px;">
  26. <h3>It is strongly recommended to update firmware and content of /html directory on SD-card at the same time!</h3>
  27. <h2>1. Firmware Update</h2>
  28. <table class="fixed" border="0">
  29. <tr>
  30. <td>
  31. <table border="0">
  32. <tr>
  33. <td style="width: 230px">
  34. <label for="newfile">Select the firmware file:</label>
  35. </td>
  36. <td colspan="2">
  37. <input id="newfile" type="file" onchange="setpath()" style="width:100%;">
  38. </td>
  39. </tr>
  40. <tr>
  41. <td>
  42. <label for="filepath">Set path on server:</label>
  43. </td>
  44. <td>
  45. <input id="filepath" type="text" style="width:100%;" readonly>
  46. </td>
  47. <td>
  48. <button id="upload" type="button" onclick="upload()">Upload</button>
  49. </td>
  50. </tr>
  51. </table>
  52. </td>
  53. </tr>
  54. <tr>
  55. <td>
  56. <table border="0">
  57. <tr>
  58. <td style="width: 230px">
  59. <button class="button" id="doUpdate" type="button" onclick="doUpdate()">Flash the firmware</button>
  60. </td>
  61. <td>
  62. (Takes about 60s)
  63. </td>
  64. </tr>
  65. </table>
  66. </td>
  67. </tr>
  68. </table>
  69. <h2>2. Update "/html" directory</h2>
  70. <table class="fixed" border="0">
  71. <tr>
  72. <td>
  73. <table border="0">
  74. <tr>
  75. <td style="width: 230px">
  76. <label for="newfilehtml">Select the zipped /html content:</label>
  77. </td>
  78. <td colspan="2">
  79. <input id="newfilehtml" type="file" onchange="setpathhtml()" style="width:100%;">
  80. </td>
  81. </tr>
  82. <tr>
  83. <td>
  84. <label for="filepathhtml">Set path on server:</label>
  85. </td>
  86. <td>
  87. <input id="filepathhtml" type="text" style="width:100%;" readonly>
  88. </td>
  89. <td>
  90. <button id="uploadhtml" type="button" onclick="uploadhtml()">Upload</button>
  91. </td>
  92. </tr>
  93. </table>
  94. </td>
  95. </tr>
  96. <tr>
  97. <td>
  98. <button class="button" id="doUpdatehtml" type="button" onclick="doUpdatehtml()">Update "/html" directory</button>
  99. </td>
  100. </tr>
  101. </table>
  102. <h2>3. Reboot</h2>
  103. <table class="fixed" border="0">
  104. <tr>
  105. <td>
  106. <button class="button" id="reboot" type="button" onclick="doReboot()">Reboot to activate updates</button>
  107. </td>
  108. </tr>
  109. </table>
  110. <script type="text/javascript" src="./gethost.js"></script>
  111. <script language="JavaScript">
  112. function init(){
  113. document.getElementById("reboot").disabled = true;
  114. document.getElementById("upload").disabled = true;
  115. document.getElementById("uploadhtml").disabled = true;
  116. document.getElementById("doUpdate").disabled = true;
  117. document.getElementById("doUpdatehtml").disabled = true;
  118. }
  119. function doUpdate() {
  120. if (confirm("Are you sure to update the firmware?")) {
  121. var stringota = "/ota?file=firmware.bin";
  122. var xhttp = new XMLHttpRequest();
  123. xhttp.onreadystatechange = function() {
  124. if (xhttp.readyState == 4) {
  125. if (xhttp.status == 200) {
  126. document.getElementById("reboot").disabled = false;
  127. alert("Flash successfull - Reboot necessary to make changes active.");
  128. /* keine Reaktion, damit sich das Dokument nicht ändert */
  129. } else if (xhttp.status == 0) {
  130. alert("Server closed the connection abruptly!");
  131. UpdatePage();
  132. } else {
  133. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  134. UpdatePage();
  135. }
  136. }
  137. };
  138. xhttp.open("GET", stringota, true);
  139. xhttp.send();
  140. }
  141. }
  142. function doUpdatehtml() {
  143. if (confirm("Are you sure to update the /html content?")) {
  144. var stringota = "/ota?task=unziphtml";
  145. var xhttp = new XMLHttpRequest();
  146. xhttp.onreadystatechange = function() {
  147. if (xhttp.readyState == 4) {
  148. if (xhttp.status == 200) {
  149. document.getElementById("reboot").disabled = false;
  150. alert("Update /html successful!");
  151. /* keine Reaktion, damit sich das Dokument nicht ändert */
  152. } else if (xhttp.status == 0) {
  153. alert("Server closed the connection abruptly!");
  154. UpdatePage();
  155. } else {
  156. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  157. UpdatePage();
  158. }
  159. }
  160. };
  161. xhttp.open("GET", stringota, true);
  162. xhttp.send();
  163. }
  164. }
  165. function doReboot() {
  166. if (confirm("Are you sure you want to reboot the ESP32?")) {
  167. var stringota = "/reboot";
  168. window.location = stringota;
  169. window.location.href = stringota;
  170. window.location.assign(stringota);
  171. window.location.replace(stringota);
  172. }
  173. }
  174. function setpath() {
  175. var fileserverpraefix = "/firmware/firmware.bin";
  176. document.getElementById("filepath").value = fileserverpraefix;
  177. document.getElementById("upload").disabled = false;
  178. }
  179. function setpathhtml() {
  180. var fileserverpraefix = "/firmware/html.zip";
  181. document.getElementById("filepathhtml").value = fileserverpraefix;
  182. document.getElementById("uploadhtml").disabled = false;
  183. }
  184. function upload() {
  185. var xhttp = new XMLHttpRequest();
  186. /* first delete the old firmware */
  187. xhttp.onreadystatechange = function() {
  188. if (xhttp.readyState == 4) {
  189. if (xhttp.status == 200) {
  190. /* keine Reaktion, damit sich das Dokument nicht ändert */
  191. } else if (xhttp.status == 0) {
  192. alert("Server closed the connection abruptly!");
  193. UpdatePage();
  194. } else {
  195. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  196. UpdatePage();
  197. }
  198. }
  199. };
  200. xhttp.open("GET", "/ota?delete=firmware.bin", false);
  201. xhttp.send();
  202. /* ----------------------------- */
  203. var filePath = document.getElementById("filepath").value;
  204. var upload_path = "/upload/" + filePath;
  205. var fileInput = document.getElementById("newfile").files;
  206. /* Max size of an individual file. Make sure this
  207. * value is same as that set in file_server.c */
  208. var MAX_FILE_SIZE = 2000*1024;
  209. var MAX_FILE_SIZE_STR = "2000KB";
  210. if (fileInput.length == 0) {
  211. alert("No file selected!");
  212. } else if (filePath.length == 0) {
  213. alert("File path on server is not set!");
  214. } else if (filePath.indexOf(' ') >= 0) {
  215. alert("File path on server cannot have spaces!");
  216. } else if (filePath[filePath.length-1] == '/') {
  217. alert("File name not specified after path!");
  218. } else if (fileInput[0].size > 2000*1024) {
  219. alert("File size must be less than 2000KB!");
  220. } else {
  221. document.getElementById("newfile").disabled = true;
  222. document.getElementById("filepath").disabled = true;
  223. document.getElementById("upload").disabled = true;
  224. xhttp.onreadystatechange = function() {
  225. if (xhttp.readyState == 4) {
  226. if (xhttp.status == 200) {
  227. alert("Upload successfull!")
  228. // document.reload();
  229. document.getElementById("reboot").disabled = false;
  230. document.getElementById("doUpdate").disabled = false;
  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. var file = fileInput[0];
  241. xhttp.open("POST", upload_path, true);
  242. xhttp.send(file);
  243. }
  244. }
  245. function uploadhtml() {
  246. var xhttp = new XMLHttpRequest();
  247. /* first delete the old firmware */
  248. xhttp.onreadystatechange = function() {
  249. if (xhttp.readyState == 4) {
  250. if (xhttp.status == 200) {
  251. /* keine Reaktion, damit sich das Dokument nicht ändert */
  252. } else if (xhttp.status == 0) {
  253. alert("Server closed the connection abruptly!");
  254. UpdatePage();
  255. } else {
  256. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  257. UpdatePage();
  258. }
  259. }
  260. };
  261. xhttp.open("GET", "/ota?delete=html.zip", false);
  262. xhttp.send();
  263. /* ----------------------------- */
  264. var filePath = document.getElementById("filepathhtml").value;
  265. var upload_path = "/upload/" + filePath;
  266. var fileInput = document.getElementById("newfilehtml").files;
  267. /* Max size of an individual file. Make sure this
  268. * value is same as that set in file_server.c */
  269. var MAX_FILE_SIZE = 2000*1024;
  270. var MAX_FILE_SIZE_STR = "2000KB";
  271. if (fileInput.length == 0) {
  272. alert("No file selected!");
  273. } else if (filePath.length == 0) {
  274. alert("File path on server is not set!");
  275. } else if (filePath.indexOf(' ') >= 0) {
  276. alert("File path on server cannot have spaces!");
  277. } else if (filePath[filePath.length-1] == '/') {
  278. alert("File name not specified after path!");
  279. } else if (fileInput[0].size > 2000*1024) {
  280. alert("File size must be less than 2000KB!");
  281. } else {
  282. document.getElementById("newfilehtml").disabled = true;
  283. document.getElementById("filepathhtml").disabled = true;
  284. document.getElementById("uploadhtml").disabled = true;
  285. xhttp.onreadystatechange = function() {
  286. if (xhttp.readyState == 4) {
  287. if (xhttp.status == 200) {
  288. alert("Upload successfull!")
  289. // document.reload();
  290. document.getElementById("reboot").disabled = false;
  291. document.getElementById("doUpdatehtml").disabled = false;
  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. var file = fileInput[0];
  302. xhttp.open("POST", upload_path, true);
  303. xhttp.send(file);
  304. }
  305. }
  306. init();
  307. </script>
  308. </body>
  309. </html>