ota_page.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <html><head>
  2. <title>jomjol - AI on the edge</title>
  3. <meta charset="utf-8">
  4. <meta name="viewport" content="width=device-width, initial-scale=1">
  5. <script type="text/javascript">
  6. //<![CDATA[
  7. //]]>
  8. </script>
  9. </head>
  10. <body>
  11. <table class="fixed" border="0">
  12. <td>
  13. <table border="0">
  14. <tr>
  15. <td>
  16. <label for="newfile">Upload the firmware.bin</label>
  17. </td>
  18. <td colspan="2">
  19. <input id="newfile" type="file" onchange="setpath()" style="width:100%;">
  20. </td>
  21. </tr>
  22. <tr>
  23. <td>
  24. <label for="filepath">Set path on server</label>
  25. </td>
  26. <td>
  27. <input id="filepath" type="text" style="width:100%;" readonly>
  28. </td>
  29. <td>
  30. <button id="upload" type="button" onclick="upload()">Upload</button>
  31. </td>
  32. </tr>
  33. </table>
  34. </td></tr>
  35. <tr>
  36. <td>
  37. <button id="upload" type="button" onclick="doUpdate()">Do Firmware Update</button>
  38. </td>
  39. </tr>
  40. </table>
  41. <script>
  42. function doUpdate() {
  43. if (confirm("Are you sure to update the firmware?")) {
  44. var stringota = "/ota?file=firmware.bin";
  45. window.location = stringota;
  46. window.location.href = stringota;
  47. window.location.assign(stringota);
  48. window.location.replace(stringota);
  49. }
  50. }
  51. function setpath() {
  52. var fileserverpraefix = "/firmware/firmware.bin";
  53. document.getElementById("filepath").value = fileserverpraefix;
  54. }
  55. function upload() {
  56. var xhttp = new XMLHttpRequest();
  57. /* first delete the old firmware */
  58. xhttp.onreadystatechange = function() {
  59. if (xhttp.readyState == 4) {
  60. if (xhttp.status == 200) {
  61. /* keine Reaktion, damit sich das Dokument nicht ändert */
  62. } else if (xhttp.status == 0) {
  63. alert("Server closed the connection abruptly!");
  64. location.reload()
  65. } else {
  66. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  67. location.reload()
  68. }
  69. }
  70. };
  71. xhttp.open("GET", "/ota?delete=firmware.bin", false);
  72. xhttp.send();
  73. /* ----------------------------- */
  74. var filePath = document.getElementById("filepath").value;
  75. var upload_path = "/upload/" + filePath;
  76. var fileInput = document.getElementById("newfile").files;
  77. /* Max size of an individual file. Make sure this
  78. * value is same as that set in file_server.c */
  79. var MAX_FILE_SIZE = 2000*1024;
  80. var MAX_FILE_SIZE_STR = "2000KB";
  81. if (fileInput.length == 0) {
  82. alert("No file selected!");
  83. } else if (filePath.length == 0) {
  84. alert("File path on server is not set!");
  85. } else if (filePath.indexOf(' ') >= 0) {
  86. alert("File path on server cannot have spaces!");
  87. } else if (filePath[filePath.length-1] == '/') {
  88. alert("File name not specified after path!");
  89. } else if (fileInput[0].size > 2000*1024) {
  90. alert("File size must be less than 2000KB!");
  91. } else {
  92. document.getElementById("newfile").disabled = true;
  93. document.getElementById("filepath").disabled = true;
  94. document.getElementById("upload").disabled = true;
  95. xhttp.onreadystatechange = function() {
  96. if (xhttp.readyState == 4) {
  97. if (xhttp.status == 200) {
  98. alert("Upload successfull!")
  99. document.reload();
  100. } else if (xhttp.status == 0) {
  101. alert("Server closed the connection abruptly!");
  102. location.reload()
  103. } else {
  104. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  105. location.reload()
  106. }
  107. }
  108. };
  109. var file = fileInput[0];
  110. xhttp.open("POST", upload_path, true);
  111. xhttp.send(file);
  112. }
  113. }
  114. </script>
  115. </body></html>