html_confAdd.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* clang-format off */
  2. //static const char html_confadd_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(el !== null) {
  9. // if(da == '1') {
  10. // el.checked = true;
  11. // el.style.visibility = 'visible';
  12. // }
  13. // else {
  14. // el.checked = false;
  15. // el.style.visibility = 'visible';
  16. // }
  17. // }
  18. // }
  19. // function updCbxVal(el) {
  20. // if(el !== null) {
  21. // if (el.checked) el.value = '1';
  22. // else {
  23. // el.checked = true;
  24. // el.value = '0';
  25. // el.style.visibility = 'hidden';
  26. // }
  27. // }
  28. // }
  29. static const char html_confadd_script[] PROGMEM = R"=====(
  30. function transmit(f) {
  31. if (!xhttp) {
  32. reqTime = 0;
  33. reqFin = false;
  34. xhttp = new XMLHttpRequest();
  35. xhttp.timeout = 1000;
  36. xhttp.overrideMimeType('application/json');
  37. xhttp.open('POST', 'confDataAdd');
  38. xhttp.send(f ? (new FormData(f)) : '');
  39. xhttp.onreadystatechange = function () {
  40. if (xhttp.readyState === XMLHttpRequest.DONE && xhttp.status === 200) {
  41. var data = JSON.parse(xhttp.responseText);
  42. g('PIRTop').value = data.PIRTop;
  43. g('PIROnPld').value = data.PIROnPld;
  44. g('PIROffPld').value = data.PIROffPld;
  45. g('outTempTop').value = data.outTempTop;
  46. g('outHumTop').value = data.outHumTop;
  47. xhttp = null;
  48. reqFin = true;
  49. }
  50. else {
  51. if(!reqFin && reqTime > 10) {
  52. xhttp = null;
  53. reqFin = true;
  54. }
  55. }
  56. }
  57. }
  58. return false;
  59. }
  60. //transmit();
  61. function saveConf() {
  62. g('frmConf').submit();
  63. }
  64. function init() {
  65. transmit();
  66. }
  67. )====="; // html_confadd_script
  68. // setInterval(function () { ++reqTime; }, 1000);
  69. //</script>
  70. //)====="; // html_confadd_script
  71. static const char html_confadd_body[] PROGMEM = R"=====(
  72. <b>Configuration - Additional Functions</b>
  73. <div class='config'>
  74. <form id='frmConf' action='setConfAdd' method='POST'>
  75. <br>
  76. <fieldset>
  77. <legend>PIR Sensor</legend>
  78. <p><b>MQTT Publish Topic</b><br><input type='text' name='PIRTop' id='PIRTop'/></p>
  79. <p><b>MQTT ON Payload</b><br><input type='text' name='PIROnPld' id='PIROnPld'/></p>
  80. <p><b>MQTT OFF Payload</b><br><input type='text' name='PIROffPld' id='PIROffPld'/></p>
  81. </fieldset>
  82. <div></div><br>
  83. <fieldset>
  84. <legend>Outside Temp/Hum via MQTT</legend>
  85. <p class='n'>Only used if not empty, can be subscribed to and valid data is sent. </p>
  86. <p><b>O-Temp In-Topic</b><br><input type='text' name='outTempTop' id='outTempTop'/></p>
  87. <p><b>O-Hum In-Topic</b><br><input type='text' name='outHumTop' id='outHumTop'/><br>
  88. </fieldset>
  89. <br>
  90. </form>
  91. <div></div>
  92. <table style='width:100%'>
  93. <td style='width:50%'><button onclick='location="conf";' class='bgrey'>Cancel</button></td>
  94. <td style='width:50%'><button onclick='return saveConf()' class='bred'>Save</button></td>
  95. </tr></table>
  96. </div>
  97. )====="; // html_confadd_body