ota_html.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. .reg-row td { font-family: monospace; font-size: 0.85rem; padding: 2px 8px; }
  21. .reg-row td:first-child { color: #6c757d; width: 120px; }
  22. </style>
  23. </head>
  24. <body>
  25. <div class="container ota-card">
  26. <h4 class="mb-1"><i class="fa fa-microchip"></i> Device Management</h4>
  27. <p class="text-muted small mb-2">Device: <strong>{{IP}}</strong></p>
  28. <!-- DSP live status card -->
  29. <div class="card mb-4">
  30. <div class="card-header d-flex justify-content-between align-items-center py-2">
  31. <span class="small fw-semibold"><i class="fa fa-tachometer"></i> DSP Status</span>
  32. <span id="dspBadge" class="badge bg-secondary">Polling&hellip;</span>
  33. </div>
  34. <div class="card-body py-2 px-3">
  35. <table class="w-100">
  36. <tr class="reg-row"><td>Core Register</td><td id="sCoreReg">&mdash;</td></tr>
  37. <tr class="reg-row"><td>Running</td> <td id="sRunning">&mdash;</td></tr>
  38. <tr class="reg-row"><td>GPIO</td> <td id="sGpio">&mdash;</td></tr>
  39. <tr class="reg-row"><td>ADC 0&ndash;3</td><td id="sAdc">&mdash;</td></tr>
  40. </table>
  41. <p class="text-muted mb-0 mt-1" style="font-size:0.72rem">
  42. Updated <span id="sUpdated">&mdash;</span> &bull; auto-refreshes every 2 s
  43. </p>
  44. </div>
  45. </div>
  46. <form id="otaForm" action="/ota_do" method="POST" enctype="multipart/form-data">
  47. <div class="mb-3">
  48. <label class="form-label fw-semibold">Firmware binary (.bin)</label>
  49. <input class="form-control" type="file" id="fwFile" name="firmware" accept=".bin" required>
  50. <div class="form-text">Export from Arduino IDE: <em>Sketch &rarr; Export Compiled Binary</em></div>
  51. </div>
  52. <button type="submit" id="flashBtn" class="btn btn-warning w-100">
  53. <i class="fa fa-upload"></i>&nbsp; Flash Firmware
  54. </button>
  55. </form>
  56. <div id="progressWrap">
  57. <div class="progress" style="height:22px">
  58. <div class="progress-bar progress-bar-striped progress-bar-animated bg-warning"
  59. style="width:100%; font-size:0.8rem; line-height:22px">
  60. Uploading&hellip;
  61. </div>
  62. </div>
  63. <p class="text-center text-muted small mt-2">
  64. <i class="fa fa-spinner fa-spin"></i>
  65. Do not power off the device.
  66. </p>
  67. </div>
  68. <div id="resultBox" class="alert" role="alert"></div>
  69. <hr class="mt-4">
  70. <h6 class="text-muted mb-2"><i class="fa fa-refresh"></i> DSP Control</h6>
  71. <button id="resetBtn" class="btn btn-outline-secondary w-100"
  72. onclick="dspReset()">
  73. <i class="fa fa-power-off"></i>&nbsp; Soft Reset DSP
  74. </button>
  75. <div class="form-text mb-1">
  76. Restarts DSP program execution. RAM is preserved — does not reload from EEPROM.
  77. </div>
  78. <div id="resetResult" class="alert alert-sm" role="alert"></div>
  79. <hr class="mt-3">
  80. <a href="/" class="text-muted small"><i class="fa fa-arrow-left"></i> Back to EEPROM Uploader</a>
  81. </div>
  82. <script>
  83. function pollStatus() {
  84. var xhr = new XMLHttpRequest();
  85. xhr.open('GET', '/dsp_status', true);
  86. xhr.timeout = 1800;
  87. xhr.onload = function() {
  88. var badge = document.getElementById('dspBadge');
  89. if (xhr.status !== 200) {
  90. badge.className = 'badge bg-danger'; badge.textContent = 'I2C Error';
  91. return;
  92. }
  93. try {
  94. var d = JSON.parse(xhr.responseText);
  95. if (d.running) {
  96. badge.className = 'badge bg-success'; badge.textContent = 'Running';
  97. } else {
  98. badge.className = 'badge bg-danger'; badge.textContent = 'Stopped';
  99. }
  100. document.getElementById('sCoreReg').textContent = d.coreReg;
  101. document.getElementById('sRunning').textContent = d.running ? 'Yes' : 'No';
  102. document.getElementById('sGpio').textContent = d.gpio;
  103. document.getElementById('sAdc').textContent = d.adc.join(' ');
  104. document.getElementById('sUpdated').textContent =
  105. new Date().toLocaleTimeString();
  106. } catch(e) {
  107. badge.className = 'badge bg-warning'; badge.textContent = 'Parse error';
  108. }
  109. };
  110. xhr.ontimeout = xhr.onerror = function() {
  111. var badge = document.getElementById('dspBadge');
  112. badge.className = 'badge bg-secondary'; badge.textContent = 'Offline';
  113. };
  114. xhr.send();
  115. }
  116. pollStatus();
  117. setInterval(pollStatus, 2000);
  118. function dspReset() {
  119. var btn = document.getElementById('resetBtn');
  120. var box = document.getElementById('resetResult');
  121. btn.disabled = true;
  122. box.style.display = 'none';
  123. var xhr = new XMLHttpRequest();
  124. xhr.open('POST', '/dsp_reset', true);
  125. xhr.onload = function() {
  126. box.style.display = 'block';
  127. if (xhr.status === 200) {
  128. box.className = 'alert alert-success alert-sm';
  129. box.innerHTML = '<i class="fa fa-check"></i> ' + xhr.responseText;
  130. } else {
  131. box.className = 'alert alert-danger alert-sm';
  132. box.innerHTML = '<i class="fa fa-times"></i> Reset failed.';
  133. }
  134. btn.disabled = false;
  135. };
  136. xhr.onerror = function() {
  137. box.style.display = 'block';
  138. box.className = 'alert alert-danger alert-sm';
  139. box.innerHTML = '<i class="fa fa-times"></i> Request failed.';
  140. btn.disabled = false;
  141. };
  142. xhr.send();
  143. }
  144. document.getElementById('otaForm').addEventListener('submit', function(e) {
  145. e.preventDefault();
  146. var file = document.getElementById('fwFile').files[0];
  147. if (!file) return;
  148. document.getElementById('flashBtn').disabled = true;
  149. document.getElementById('progressWrap').style.display = 'block';
  150. document.getElementById('resultBox').style.display = 'none';
  151. var fd = new FormData(this);
  152. var xhr = new XMLHttpRequest();
  153. xhr.open('POST', '/ota_do', true);
  154. xhr.onload = function() {
  155. document.getElementById('progressWrap').style.display = 'none';
  156. var box = document.getElementById('resultBox');
  157. box.style.display = 'block';
  158. if (xhr.status === 200) {
  159. box.className = 'alert alert-success';
  160. box.innerHTML = '<i class="fa fa-check-circle"></i> ' + xhr.responseText +
  161. '<br><small>Reconnecting in 5 seconds&hellip;</small>';
  162. setTimeout(function(){ window.location.href = '/'; }, 5500);
  163. } else {
  164. box.className = 'alert alert-danger';
  165. box.innerHTML = '<i class="fa fa-times-circle"></i> ' + xhr.responseText;
  166. document.getElementById('flashBtn').disabled = false;
  167. }
  168. };
  169. xhr.onerror = function() {
  170. document.getElementById('progressWrap').style.display = 'none';
  171. var box = document.getElementById('resultBox');
  172. box.style.display = 'block';
  173. box.className = 'alert alert-danger';
  174. box.innerHTML = '<i class="fa fa-times-circle"></i> Upload error — check Serial log.';
  175. document.getElementById('flashBtn').disabled = false;
  176. };
  177. xhr.send(fd);
  178. });
  179. </script>
  180. </body>
  181. </html>
  182. )HTML";