ota_html.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #pragma once
  2. #include <pgmspace.h>
  3. static const char OTA_HTML[] PROGMEM = R"HTML(
  4. <!doctype html>
  5. <html lang="en-AU">
  6. <head>
  7. <meta charset="utf-8">
  8. <meta name="viewport" content="width=device-width, initial-scale=1">
  9. <link rel="icon" type="image/x-icon" href="/favicon.ico">
  10. <link rel="stylesheet" href="yeti-bootstrap.min.css">
  11. <link rel="stylesheet" href="font-awesome.min.css">
  12. <script src="jquery-3.7.1.slim.min.js" crossorigin="anonymous"></script>
  13. <title>Modulos DSP - Device Management</title>
  14. <style>
  15. body { padding-top: 40px; }
  16. .ota-card { max-width: 520px; margin: 0 auto; }
  17. #progressWrap { display: none; margin-top: 1.2rem; }
  18. #resultBox { display: none; margin-top: 1rem; }
  19. #resetResult { display: none; margin-top: 0.6rem; }
  20. </style>
  21. </head>
  22. <body>
  23. <div class="container ota-card">
  24. <h4 class="mb-1"><i class="fa fa-microchip"></i> Device Management</h4>
  25. <p class="text-muted small mb-4">Device: <strong>{{IP}}</strong></p>
  26. <form id="otaForm" action="/ota_do" method="POST" enctype="multipart/form-data">
  27. <div class="mb-3">
  28. <label class="form-label fw-semibold">Firmware binary (.bin)</label>
  29. <input class="form-control" type="file" id="fwFile" name="firmware" accept=".bin" required>
  30. <div class="form-text">Export from Arduino IDE: <em>Sketch &rarr; Export Compiled Binary</em></div>
  31. </div>
  32. <button type="submit" id="flashBtn" class="btn btn-warning w-100">
  33. <i class="fa fa-upload"></i>&nbsp; Flash Firmware
  34. </button>
  35. </form>
  36. <div id="progressWrap">
  37. <div class="progress" style="height:22px">
  38. <div class="progress-bar progress-bar-striped progress-bar-animated bg-warning"
  39. style="width:100%; font-size:0.8rem; line-height:22px">
  40. Uploading&hellip;
  41. </div>
  42. </div>
  43. <p class="text-center text-muted small mt-2">
  44. <i class="fa fa-spinner fa-spin"></i>
  45. Do not power off the device.
  46. </p>
  47. </div>
  48. <div id="resultBox" class="alert" role="alert"></div>
  49. <hr class="mt-4">
  50. <h6 class="text-muted mb-2"><i class="fa fa-refresh"></i> DSP Control</h6>
  51. <button id="resetBtn" class="btn btn-outline-secondary w-100"
  52. onclick="dspReset()">
  53. <i class="fa fa-power-off"></i>&nbsp; Soft Reset DSP
  54. </button>
  55. <div class="form-text mb-1">
  56. Restarts DSP program execution. RAM is preserved — does not reload from EEPROM.
  57. </div>
  58. <div id="resetResult" class="alert alert-sm" role="alert"></div>
  59. <hr class="mt-3">
  60. <a href="/" class="text-muted small"><i class="fa fa-arrow-left"></i> Back to EEPROM Uploader</a>
  61. </div>
  62. <script>
  63. function dspReset() {
  64. var btn = document.getElementById('resetBtn');
  65. var box = document.getElementById('resetResult');
  66. btn.disabled = true;
  67. box.style.display = 'none';
  68. var xhr = new XMLHttpRequest();
  69. xhr.open('POST', '/dsp_reset', true);
  70. xhr.onload = function() {
  71. box.style.display = 'block';
  72. if (xhr.status === 200) {
  73. box.className = 'alert alert-success alert-sm';
  74. box.innerHTML = '<i class="fa fa-check"></i> ' + xhr.responseText;
  75. } else {
  76. box.className = 'alert alert-danger alert-sm';
  77. box.innerHTML = '<i class="fa fa-times"></i> Reset failed.';
  78. }
  79. btn.disabled = false;
  80. };
  81. xhr.onerror = function() {
  82. box.style.display = 'block';
  83. box.className = 'alert alert-danger alert-sm';
  84. box.innerHTML = '<i class="fa fa-times"></i> Request failed.';
  85. btn.disabled = false;
  86. };
  87. xhr.send();
  88. }
  89. document.getElementById('otaForm').addEventListener('submit', function(e) {
  90. e.preventDefault();
  91. var file = document.getElementById('fwFile').files[0];
  92. if (!file) return;
  93. document.getElementById('flashBtn').disabled = true;
  94. document.getElementById('progressWrap').style.display = 'block';
  95. document.getElementById('resultBox').style.display = 'none';
  96. var fd = new FormData(this);
  97. var xhr = new XMLHttpRequest();
  98. xhr.open('POST', '/ota_do', true);
  99. xhr.onload = function() {
  100. document.getElementById('progressWrap').style.display = 'none';
  101. var box = document.getElementById('resultBox');
  102. box.style.display = 'block';
  103. if (xhr.status === 200) {
  104. box.className = 'alert alert-success';
  105. box.innerHTML = '<i class="fa fa-check-circle"></i> ' + xhr.responseText +
  106. '<br><small>Reconnecting in 5 seconds&hellip;</small>';
  107. setTimeout(function(){ window.location.href = '/'; }, 5500);
  108. } else {
  109. box.className = 'alert alert-danger';
  110. box.innerHTML = '<i class="fa fa-times-circle"></i> ' + xhr.responseText;
  111. document.getElementById('flashBtn').disabled = false;
  112. }
  113. };
  114. xhr.onerror = function() {
  115. document.getElementById('progressWrap').style.display = 'none';
  116. var box = document.getElementById('resultBox');
  117. box.style.display = 'block';
  118. box.className = 'alert alert-danger';
  119. box.innerHTML = '<i class="fa fa-times-circle"></i> Upload error — check Serial log.';
  120. document.getElementById('flashBtn').disabled = false;
  121. };
  122. xhr.send(fd);
  123. });
  124. </script>
  125. </body>
  126. </html>
  127. )HTML";