html_confadd.ino 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. static const char html_confadd_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', 'confdadd');
  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('PIRTop').value = data.PIRTop;
  37. g('PIROnPld').value = data.PIROnPld;
  38. g('PIROffPld').value = data.PIROffPld;
  39. g('outTempTop').value = data.outTempTop;
  40. g('outHumTop').value = data.outHumTop;
  41. xhttp = null;
  42. reqFin = true;
  43. }
  44. else {
  45. if(!reqFin && reqTime > 10) {
  46. xhttp = null;
  47. reqFin = true;
  48. }
  49. }
  50. }
  51. }
  52. return false;
  53. }
  54. //transmit();
  55. function saveConf() {
  56. g('frmConf').submit();
  57. }
  58. function init() {
  59. transmit();
  60. }
  61. setInterval(function () { ++reqTime; }, 1000);
  62. </script>
  63. )====="; // html_confadd_script
  64. static const char html_confadd_body[] PROGMEM = R"=====(
  65. <b>Configuration - Additional Functions</b>
  66. <div class='config'>
  67. <form id='frmConf' action='setConfAdd' method='POST'>
  68. <br>
  69. <fieldset>
  70. <legend>PIR Sensor</legend>
  71. <p><b>MQTT Publish Topic</b><br><input type='text' name='PIRTop' id='PIRTop'/></p>
  72. <p><b>MQTT ON Payload</b><br><input type='text' name='PIROnPld' id='PIROnPld'/></p>
  73. <p><b>MQTT OFF Payload</b><br><input type='text' name='PIROffPld' id='PIROffPld'/></p>
  74. </fieldset>
  75. <div></div><br>
  76. <fieldset>
  77. <legend>Outside Temp/Hum via MQTT</legend>
  78. <p style='font-weight:normal;font-size:0.8em;'>Only used if not empty, can be subscribed to and valid data is sent. </p>
  79. <p><b>O-Temp In-Topic</b><br><input type='text' name='outTempTop' id='outTempTop'/></p>
  80. <p><b>O-Hum In-Topic</b><br><input type='text' name='outHumTop' id='outHumTop'/><br>
  81. </fieldset>
  82. <br>
  83. </form>
  84. <div></div>
  85. <table style='width:100%'>
  86. <td style='width:50%'><button onclick='location="conf";' class='bgrey'>Cancel</button></td>
  87. <td style='width:50%'><button onclick='return saveConf()' class='bred'>Save</button></td>
  88. </tr></table>
  89. </div>
  90. )====="; // html_confadd_body