html_confdev.ino 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. static const char html_confdev_script[] PROGMEM = R"=====(
  2. <script>
  3. function g(i) { return document.getElementById(i) };
  4. function sp(i){g(i).type=(g(i).type==='text'?'password':'text');}
  5. var xhttp, reqTime, reqFin;
  6. function setCbx(el, da) {
  7. if(da == '1') {
  8. el.checked = true;
  9. el.style.visibility = 'visible';
  10. }
  11. else {
  12. el.checked = false;
  13. el.style.visibility = 'visible';
  14. }
  15. }
  16. function updCbxVal(el) {
  17. if (el.checked) el.value = '1';
  18. else {
  19. el.checked = true;
  20. el.value = '0';
  21. el.style.visibility = 'hidden';
  22. }
  23. }
  24. function transmit(f) {
  25. if (!xhttp) {
  26. reqTime = 0;
  27. reqFin = false;
  28. xhttp = new XMLHttpRequest();
  29. xhttp.timeout = 1000;
  30. xhttp.overrideMimeType('application/json');
  31. xhttp.open('POST', 'confddev');
  32. xhttp.send(f ? (new FormData(f)) : '');
  33. xhttp.onreadystatechange = function () {
  34. if (xhttp.readyState === XMLHttpRequest.DONE && xhttp.status === 200) {
  35. var data = JSON.parse(xhttp.responseText);
  36. g('devName').value = data.devName;
  37. g('hostName').value = data.hostName;
  38. g('wifiappw').value = data.wifiappw;
  39. xhttp = null;
  40. reqFin = true;
  41. }
  42. else {
  43. if(!reqFin && reqTime > 10) {
  44. xhttp = null;
  45. reqFin = true;
  46. }
  47. }
  48. }
  49. }
  50. return false;
  51. }
  52. //transmit();
  53. function saveConf() {
  54. g('frmConf').submit();
  55. }
  56. function init() {
  57. transmit();
  58. setCbx(g('wifiappwSet'), 0);
  59. }
  60. setInterval(function () { ++reqTime; }, 1000);
  61. </script>
  62. )====="; // html_confdev_script
  63. static const char html_confdev_body[] PROGMEM = R"=====(
  64. <b>Configuration - Device</b>
  65. <div class='config'>
  66. <form id='frmConf' action='setConfDev' method='POST'>
  67. <br>
  68. <fieldset>
  69. <legend>Device</legend>
  70. <p><b>Device Name *</b><br><input type='text' name='devName' id='devName'></p>
  71. <p><b>Hostname *</b><br><input type='text' name='hostName' id='hostName'></p>
  72. <p><b>WiFi AP Password *</b><input type='checkbox' id='wifiappwSet' name='wifiappwSet' onclick='sp("wifiappw")'><br><input type='password' name='wifiappw' id='wifiappw'></p>
  73. </fieldset>
  74. <br>
  75. </form>
  76. <div></div>
  77. <table style='width:100%'>
  78. <td style='width:50%'><button onclick='location="conf";' class='bgrey'>Cancel</button></td>
  79. <td style='width:50%'><button onclick='return saveConf()' class='bred'>Save</button></td>
  80. </tr></table>
  81. </div>
  82. )====="; // html_confdev_body