ota_html.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. <h6 class="text-muted mb-2"><i class="fa fa-toggle-on"></i> GPIO Control</h6>
  81. <div class="d-flex gap-2 mb-1">
  82. <button id="gp0" class="btn btn-outline-secondary btn-sm" onclick="toggleGpioPin(0)">GP0</button>
  83. <button id="gp1" class="btn btn-outline-secondary btn-sm" onclick="toggleGpioPin(1)">GP1</button>
  84. <button id="gp2" class="btn btn-outline-secondary btn-sm" onclick="toggleGpioPin(2)">GP2</button>
  85. <button id="gp3" class="btn btn-outline-secondary btn-sm" onclick="toggleGpioPin(3)">GP3</button>
  86. </div>
  87. <div class="form-text mb-1">
  88. Writes to GPIO All Register (0x0808). Only output-configured pins respond (set via MpCfg).
  89. </div>
  90. <div id="gpioResult" style="display:none; margin-top:0.4rem;" class="alert alert-sm" role="alert"></div>
  91. <hr class="mt-3">
  92. <h6 class="text-muted mb-2"><i class="fa fa-wifi"></i> WiFi Settings</h6>
  93. <button class="btn btn-outline-danger w-100" onclick="wifiReset()">
  94. <i class="fa fa-trash-o"></i>&nbsp; Reset WiFi Credentials
  95. </button>
  96. <div class="form-text mb-1">
  97. Clears stored credentials and reboots into setup mode.
  98. Connect to <strong>ModulosDSP-Setup</strong> then open <strong>192.168.4.1</strong> to reconfigure.
  99. </div>
  100. <div id="wifiResetResult" style="display:none; margin-top:0.4rem;" class="alert alert-sm" role="alert"></div>
  101. <hr class="mt-3">
  102. <a href="/" class="text-muted small"><i class="fa fa-arrow-left"></i> Back to EEPROM Uploader</a>
  103. </div>
  104. <script>
  105. function pollStatus() {
  106. var xhr = new XMLHttpRequest();
  107. xhr.open('GET', '/dsp_status', true);
  108. xhr.timeout = 1800;
  109. xhr.onload = function() {
  110. var badge = document.getElementById('dspBadge');
  111. if (xhr.status !== 200) {
  112. badge.className = 'badge bg-danger'; badge.textContent = 'I2C Error';
  113. return;
  114. }
  115. try {
  116. var d = JSON.parse(xhr.responseText);
  117. if (d.running) {
  118. badge.className = 'badge bg-success'; badge.textContent = 'Running';
  119. } else {
  120. badge.className = 'badge bg-danger'; badge.textContent = 'Stopped';
  121. }
  122. document.getElementById('sCoreReg').textContent = d.coreReg;
  123. document.getElementById('sRunning').textContent = d.running ? 'Yes' : 'No';
  124. document.getElementById('sGpio').textContent = d.gpio;
  125. document.getElementById('sAdc').textContent = d.adc.join(' ');
  126. document.getElementById('sUpdated').textContent =
  127. new Date().toLocaleTimeString();
  128. } catch(e) {
  129. badge.className = 'badge bg-warning'; badge.textContent = 'Parse error';
  130. }
  131. };
  132. xhr.ontimeout = xhr.onerror = function() {
  133. var badge = document.getElementById('dspBadge');
  134. badge.className = 'badge bg-secondary'; badge.textContent = 'Offline';
  135. };
  136. xhr.send();
  137. }
  138. pollStatus();
  139. setInterval(pollStatus, 2000);
  140. function dspReset() {
  141. var btn = document.getElementById('resetBtn');
  142. var box = document.getElementById('resetResult');
  143. btn.disabled = true;
  144. box.style.display = 'none';
  145. var xhr = new XMLHttpRequest();
  146. xhr.open('POST', '/dsp_reset', true);
  147. xhr.onload = function() {
  148. box.style.display = 'block';
  149. if (xhr.status === 200) {
  150. box.className = 'alert alert-success alert-sm';
  151. box.innerHTML = '<i class="fa fa-check"></i> ' + xhr.responseText;
  152. } else {
  153. box.className = 'alert alert-danger alert-sm';
  154. box.innerHTML = '<i class="fa fa-times"></i> Reset failed.';
  155. }
  156. btn.disabled = false;
  157. };
  158. xhr.onerror = function() {
  159. box.style.display = 'block';
  160. box.className = 'alert alert-danger alert-sm';
  161. box.innerHTML = '<i class="fa fa-times"></i> Request failed.';
  162. btn.disabled = false;
  163. };
  164. xhr.send();
  165. }
  166. var gpioVal = null;
  167. function updateGpioBtns(val) {
  168. for (var i = 0; i < 4; i++) {
  169. var btn = document.getElementById('gp' + i);
  170. if (val & (1 << i)) {
  171. btn.className = 'btn btn-success btn-sm';
  172. } else {
  173. btn.className = 'btn btn-outline-secondary btn-sm';
  174. }
  175. }
  176. }
  177. function fetchGpio() {
  178. var xhr = new XMLHttpRequest();
  179. xhr.open('GET', '/gpio', true);
  180. xhr.timeout = 1800;
  181. xhr.onload = function() {
  182. if (xhr.status === 200) {
  183. try {
  184. var d = JSON.parse(xhr.responseText);
  185. gpioVal = d.gpio;
  186. updateGpioBtns(gpioVal);
  187. } catch(e) {}
  188. }
  189. };
  190. xhr.send();
  191. }
  192. function toggleGpioPin(pin) {
  193. if (gpioVal === null) return;
  194. gpioVal ^= (1 << pin);
  195. updateGpioBtns(gpioVal);
  196. var box = document.getElementById('gpioResult');
  197. var xhr = new XMLHttpRequest();
  198. xhr.open('POST', '/gpio', true);
  199. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  200. xhr.onload = function() {
  201. box.style.display = 'block';
  202. if (xhr.status === 200) {
  203. box.className = 'alert alert-success alert-sm';
  204. box.innerHTML = '<i class="fa fa-check"></i> GP' + pin + ' toggled (0x' +
  205. (gpioVal & 0xFF).toString(16).padStart(2,'0').toUpperCase() + ')';
  206. } else {
  207. box.className = 'alert alert-danger alert-sm';
  208. box.innerHTML = '<i class="fa fa-times"></i> GPIO write failed.';
  209. }
  210. };
  211. xhr.onerror = function() {
  212. box.style.display = 'block';
  213. box.className = 'alert alert-danger alert-sm';
  214. box.innerHTML = '<i class="fa fa-times"></i> Request failed.';
  215. };
  216. xhr.send('value=' + gpioVal);
  217. }
  218. fetchGpio();
  219. setInterval(fetchGpio, 5000);
  220. function wifiReset() {
  221. if (!confirm('Clear WiFi credentials and reboot into setup mode?')) return;
  222. var box = document.getElementById('wifiResetResult');
  223. var xhr = new XMLHttpRequest();
  224. xhr.open('POST', '/wifi_reset', true);
  225. xhr.onload = function() {
  226. box.style.display = 'block';
  227. box.className = 'alert alert-warning alert-sm';
  228. box.innerHTML = '<i class="fa fa-info-circle"></i> ' + xhr.responseText;
  229. };
  230. xhr.onerror = function() {
  231. box.style.display = 'block';
  232. box.className = 'alert alert-danger alert-sm';
  233. box.innerHTML = '<i class="fa fa-times"></i> Request failed.';
  234. };
  235. xhr.send();
  236. }
  237. document.getElementById('otaForm').addEventListener('submit', function(e) {
  238. e.preventDefault();
  239. var file = document.getElementById('fwFile').files[0];
  240. if (!file) return;
  241. document.getElementById('flashBtn').disabled = true;
  242. document.getElementById('progressWrap').style.display = 'block';
  243. document.getElementById('resultBox').style.display = 'none';
  244. var fd = new FormData(this);
  245. var xhr = new XMLHttpRequest();
  246. xhr.open('POST', '/ota_do', true);
  247. xhr.onload = function() {
  248. document.getElementById('progressWrap').style.display = 'none';
  249. var box = document.getElementById('resultBox');
  250. box.style.display = 'block';
  251. if (xhr.status === 200) {
  252. box.className = 'alert alert-success';
  253. box.innerHTML = '<i class="fa fa-check-circle"></i> ' + xhr.responseText +
  254. '<br><small>Reconnecting in 5 seconds&hellip;</small>';
  255. setTimeout(function(){ window.location.href = '/'; }, 5500);
  256. } else {
  257. box.className = 'alert alert-danger';
  258. box.innerHTML = '<i class="fa fa-times-circle"></i> ' + xhr.responseText;
  259. document.getElementById('flashBtn').disabled = false;
  260. }
  261. };
  262. xhr.onerror = function() {
  263. document.getElementById('progressWrap').style.display = 'none';
  264. var box = document.getElementById('resultBox');
  265. box.style.display = 'block';
  266. box.className = 'alert alert-danger';
  267. box.innerHTML = '<i class="fa fa-times-circle"></i> Upload error — check Serial log.';
  268. document.getElementById('flashBtn').disabled = false;
  269. };
  270. xhr.send(fd);
  271. });
  272. </script>
  273. </body>
  274. </html>
  275. )HTML";