ota_html.h 3.6 KB

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