html_confDevWiFi.h 5.5 KB

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