html_confDevWiFi.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* clang-format off */
  2. static const char html_confDevWiFi_script[] PROGMEM = R"=====(
  3. <script>
  4. function g(i) { return document.getElementById(i) };
  5. function sp(i){g(i).type=(g(i).type==='text'?'password':'text');}
  6. var xhttp, reqTime, reqFin;
  7. function setCbx(el, da) {
  8. if(da == '1') {
  9. el.checked = true;
  10. el.style.visibility = 'visible';
  11. }
  12. else {
  13. el.checked = false;
  14. el.style.visibility = 'visible';
  15. }
  16. }
  17. function updCbxVal(el) {
  18. if (el.checked) el.value = '1';
  19. else {
  20. el.checked = true;
  21. el.value = '0';
  22. el.style.visibility = 'hidden';
  23. }
  24. }
  25. function transmit(f) {
  26. if (!xhttp) {
  27. reqTime = 0;
  28. reqFin = false;
  29. xhttp = new XMLHttpRequest();
  30. xhttp.timeout = 1000;
  31. xhttp.overrideMimeType('application/json');
  32. xhttp.open('POST', 'confDataDevWiFi');
  33. xhttp.send(f ? (new FormData(f)) : '');
  34. xhttp.onreadystatechange = function () {
  35. if (xhttp.readyState === XMLHttpRequest.DONE && xhttp.status === 200) {
  36. var data = JSON.parse(xhttp.responseText);
  37. g('devName').value = data.devName;
  38. g('hostName').value = data.hostName;
  39. g('SSID1').value = data.SSID1;
  40. g('WPW1').value = data.WPW1;
  41. g('SSID2').value = data.SSID2;
  42. g('WPW2').value = data.WPW2;
  43. g('SSIDAP').innerHTML = data.SSIDAP;
  44. g('WPWAP').value = data.WPWAP;
  45. g('WAPtout').value = data.WAPtout;
  46. g('WConnCheck').value = data.WConnCheck;
  47. g('Wretry').value = data.Wretry;
  48. g('Wreboot').value = data.Wreboot;
  49. xhttp = null;
  50. reqFin = true;
  51. }
  52. else {
  53. if(!reqFin && reqTime > 10) {
  54. xhttp = null;
  55. reqFin = true;
  56. }
  57. }
  58. }
  59. }
  60. return false;
  61. }
  62. //transmit();
  63. function saveConf() {
  64. g('frmConf').submit();
  65. }
  66. function init() {
  67. transmit();
  68. setCbx(g('WPW1Set'), 0);
  69. setCbx(g('WPW2Set'), 0);
  70. setCbx(g('WPWAPSet'), 0);
  71. }
  72. setInterval(function () { ++reqTime; }, 1000);
  73. </script>
  74. )====="; // html_confDevWiFi_script
  75. static const char html_confDevWiFi_body[] PROGMEM = R"=====(
  76. <b>Configuration - Device & WiFi</b>
  77. <div class='config'><br>
  78. <form id='frmConf' action='setConfDevWiFi' method='POST'>
  79. <fieldset>
  80. <legend>Device</legend>
  81. <p><b>Device Name *</b><br><input type='text' name='devName' id='devName'></p>
  82. <p><b>Hostname</b><br><input type='text' name='hostName' id='hostName'></p>
  83. <p class='n'>if blank, random hostname will be generated</p>
  84. </fieldset>
  85. <br>
  86. <p class='n'>After boot, firmware will first try to connect to Main Wifi-AP, <br>
  87. then if unsuccessful Fallback-AP. <br>
  88. If both fails it switches to Configuration AP-Mode. <br>
  89. AP-Mode is disabled again after configured timeout and a reconnect to the set <br>
  90. APs is tried every some minutes as configured below. <br>
  91. If no connection can be established the module will reboot after another <br>
  92. timeout if configured. <br>
  93. Reconnect always tries Main-AP first, then Fallback-AP.</p>
  94. <div></div>
  95. <fieldset>
  96. <legend>WiFi - Default-AP</legend>
  97. <p><b>Set</b>&nbsp;<input type='checkbox' id='WPW1Set' name='WPW1Set'></p>
  98. <p><b>SSID</b><br><input type='text' length=32 name='SSID1' id='SSID1'></p>
  99. <p><b>Password</b>&nbsp;<input type='checkbox' onclick='sp("WPW1")'>&nbsp;show<br><input type='password' length=64 name='WPW1' id='WPW1'></p>
  100. </fieldset>
  101. <br>
  102. <fieldset>
  103. <legend>WiFi - Fallback-AP</legend>
  104. <p><b>Set</b>&nbsp;<input type='checkbox' id='WPW2Set' name='WPW2Set'></p>
  105. <p><b>SSID</b><br><input type='text' length=32 name='SSID2' id='SSID2'></p>
  106. <p><b>Password</b>&nbsp;&nbsp;<input type='checkbox' onclick='sp("WPW2")'>&nbsp;show<br><input type='password' length=64 name='WPW2' id='WPW2'></p>
  107. </fieldset>
  108. <div></div><br>
  109. <fieldset>
  110. <legend>Configuration AP-Mode</legend>
  111. <p><b>SSID</b>: <i><span id='SSIDAP'></span></i>
  112. <p><b>Password *</b><input type='checkbox' id='WPWAPSet' name='WPWAPSet' onclick='sp("WPWAP")'><br><input type='password' name='WPWAP' id='WPWAP'></p>
  113. <p class='n'>* min. 8 chars, empty password for open WiFi</p>
  114. </fieldset>
  115. <div></div><br>
  116. <fieldset>
  117. <legend>Connection Handling</legend>
  118. <p><b>Switch off AP-Mode after [min] *</b><br><input type='number' name='WAPtout' id='WAPtout'></p>
  119. <p><b>WiFi connection check interval [s]</b><input type='number' name='WConnCheck' id='WConnCheck'></p>
  120. <p class='n'>min. 10s, max. 3600s</p><br>
  121. <p><b>Retry connecting WiFi-1 every [min] *</b><input type='number' name='Wretry' id='Wretry'></p>
  122. <p class='n'>Try WiFi-1 again when WiFi-2 is connected. <br>
  123. (prefer WiFi-1 over WiFi-2)</p><br>
  124. <p><b>Reboot if can´t connect for [min] *</b><input type='number' name='Wreboot' id='Wreboot'></p>
  125. <p class='n'>* set to 0 to disable</p>
  126. </fieldset>
  127. </form>
  128. <div></div>
  129. <table style='width:100%'>
  130. <td style='width:50%'><button onclick='location="conf";' class='bgrey'>Cancel</button></td>
  131. <td style='width:50%'><button onclick='return saveConf()' class='bred'>Save</button></td>
  132. </tr></table>
  133. </div>
  134. )====="; // html_confDevWiFi_body