ota_html.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. <title>Modulos DSP - Firmware Update</title>
  13. <style>
  14. body { padding-top: 40px; }
  15. .ota-card { max-width: 520px; margin: 0 auto; }
  16. #progressWrap { display: none; margin-top: 1.2rem; }
  17. #resultBox { display: none; margin-top: 1rem; }
  18. </style>
  19. </head>
  20. <body>
  21. <div class="container ota-card">
  22. <h4 class="mb-1"><i class="fa fa-upload"></i> Firmware Update</h4>
  23. <p class="text-muted small mb-3">Device: <strong>{{IP}}</strong></p>
  24. <form id="otaForm" action="/ota_do" method="POST" enctype="multipart/form-data">
  25. <div class="mb-3">
  26. <label class="form-label fw-semibold">Firmware binary (.bin)</label>
  27. <input class="form-control" type="file" id="fwFile" name="firmware" accept=".bin" required>
  28. <div class="form-text">Export from Arduino IDE: <em>Sketch &rarr; Export Compiled Binary</em></div>
  29. </div>
  30. <button type="submit" id="flashBtn" class="btn btn-warning w-100">
  31. <i class="fa fa-upload"></i>&nbsp; Flash Firmware
  32. </button>
  33. </form>
  34. <div id="progressWrap">
  35. <div class="progress" style="height:22px">
  36. <div class="progress-bar progress-bar-striped progress-bar-animated bg-warning"
  37. style="width:100%; font-size:0.8rem; line-height:22px">
  38. Uploading&hellip;
  39. </div>
  40. </div>
  41. <p class="text-center text-muted small mt-2">
  42. <i class="fa fa-spinner fa-spin"></i>
  43. Do not power off the device.
  44. </p>
  45. </div>
  46. <div id="resultBox" class="alert" role="alert"></div>
  47. <hr class="mt-4">
  48. <a href="/" class="text-muted small"><i class="fa fa-arrow-left"></i> Back to Device Management</a>
  49. </div>
  50. <script>
  51. document.getElementById('otaForm').addEventListener('submit', function(e) {
  52. e.preventDefault();
  53. var file = document.getElementById('fwFile').files[0];
  54. if (!file) return;
  55. document.getElementById('flashBtn').disabled = true;
  56. document.getElementById('progressWrap').style.display = 'block';
  57. document.getElementById('resultBox').style.display = 'none';
  58. var fd = new FormData(this);
  59. var xhr = new XMLHttpRequest();
  60. xhr.open('POST', '/ota_do', true);
  61. xhr.onload = function() {
  62. document.getElementById('progressWrap').style.display = 'none';
  63. var box = document.getElementById('resultBox');
  64. box.style.display = 'block';
  65. if (xhr.status === 200) {
  66. box.className = 'alert alert-success';
  67. box.innerHTML = '<i class="fa fa-check-circle"></i> ' + xhr.responseText +
  68. '<br><small>Reconnecting in 5 seconds&hellip;</small>';
  69. setTimeout(function(){ window.location.href = '/'; }, 5500);
  70. } else {
  71. box.className = 'alert alert-danger';
  72. box.innerHTML = '<i class="fa fa-times-circle"></i> ' + xhr.responseText;
  73. document.getElementById('flashBtn').disabled = false;
  74. }
  75. };
  76. xhr.onerror = function() {
  77. document.getElementById('progressWrap').style.display = 'none';
  78. var box = document.getElementById('resultBox');
  79. box.style.display = 'block';
  80. box.className = 'alert alert-danger';
  81. box.innerHTML = '<i class="fa fa-times-circle"></i> Upload error — check Serial log.';
  82. document.getElementById('flashBtn').disabled = false;
  83. };
  84. xhr.send(fd);
  85. });
  86. </script>
  87. </body>
  88. </html>
  89. )HTML";