conf2.htm 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <html><head><body>
  2. <h3>Extended configuration</h3>
  3. <a href='/'>Home</a><br><br>
  4. <input type='button' value='reload' onclick='return transmit()'/><br>
  5. <form id='form1' onsubmit='return transmit(this)'>
  6. <h4>Domoticz</h4>
  7. Domoticz Idx 1: <input type='number' name='domIdx1' id='domIdx1'/><br>
  8. Domoticz Idx 2: <input type='number' name='domIdx2' id='domIdx2'/><br>
  9. Domoticz Idx 3: <input type='number' name='domIdx3' id='domIdx3'/><br>
  10. <h4>Button MQTT-Out</h4>
  11. Retain *: <input type='checkbox' name='btnRet' id='btnRet'/><br><br>
  12. 1:<br>
  13. Topic: <input type='text' name='top1' id='top1'/> Payload: <input type='text' name='pld1' id='pld1'/><br>
  14. Hold:<br>
  15. Control relais: <select name='hld1ToRel' id='hld1ToRel'><option value='0'>-</option><option>1</option><option>2</option><option>3</option></select><br>
  16. Topic: <input type='text' name='topHld1' id='topHld1'/> Payload: <input type='text' name='pldHld1' id='pldHld1'/><br><br>
  17. 2:<br>
  18. Topic: <input type='text' name='top2' id='top2'/> Payload: <input type='text' name='pld2' id='pld2'/><br>
  19. Hold:<br>
  20. Control relais: <select name='hld2ToRel' id='hld2ToRel'><option value='0'>-</option><option>1</option><option>2</option><option>3</option></select><br>
  21. Topic: <input type='text' name='topHld2' id='topHld2'/> Payload: <input type='text' name='pldHld2' id='pldHld2'/><br><br>
  22. 3:<br>
  23. Topic: <input type='text' name='top3' id='top3'/> Payload: <input type='text' name='pld3' id='pld3'/><br>
  24. Hold:<br>
  25. Control relais: <select name='hld3ToRel' id='hld3ToRel'><option value='0'>-</option><option>1</option><option>2</option><option>3</option></select><br>
  26. Topic: <input type='text' name='topHld3' id='topHld3'/> Payload: <input type='text' name='pldHld3' id='pldHld3'/><br>
  27. <br>
  28. <input type='submit' value='Save'/>
  29. </form>
  30. <form id='rebootForm' onsubmit='return res()'>
  31. <input type='submit' value='Restart'/>
  32. </form>
  33. <script>
  34. function g(i) { return document.getElementById(i) };
  35. var xhttp, reqTime, reqFin, rxhttp;
  36. function res() {
  37. rxhttp = new XMLHttpRequest();
  38. rxhttp.timeout = 1000;
  39. rxhttp.open('POST', 'restart');
  40. rxhttp.send('');
  41. rxhttp = null;
  42. return false;
  43. }
  44. function setCheckbox(ele, dat) {
  45. if(dat == 1) {
  46. ele.checked = true;
  47. ele.style.visibility = 'visible';
  48. }
  49. else {
  50. ele.checked = false;
  51. ele.style.visibility = 'visible';
  52. }
  53. }
  54. function updateCheckboxValue(ele) {
  55. if (ele.checked) ele.value ='1';
  56. else {
  57. ele.value = '0';
  58. ele.checked = true;
  59. ele.style.visibility = 'hidden';
  60. }
  61. }
  62. function transmit(f) {
  63. if (!xhttp) {
  64. updateCheckboxValue(g('btnRet'));
  65. xhttp = new XMLHttpRequest();
  66. xhttp.timeout = 2000;
  67. xhttp.open('POST', 'confdata2');
  68. xhttp.send(f ? (new FormData(f)) : '');
  69. xhttp.onreadystatechange = function () {
  70. if (xhttp.readyState === XMLHttpRequest.DONE && xhttp.status === 200) {
  71. var data = JSON.parse(xhttp.responseText);
  72. setCheckbox(g('btnRet'), data.btnRet);
  73. g('top1').value = data.top1;
  74. g('top2').value = data.top2;
  75. g('top3').value = data.top3;
  76. g('topHld1').value = data.topHld1;
  77. g('topHld2').value = data.topHld2;
  78. g('topHld3').value = data.topHld3;
  79. g('pld1').value = data.pld1;
  80. g('pld2').value = data.pld2;
  81. g('pld3').value = data.pld3;
  82. g('pldHld1').value = data.pldHld1;
  83. g('pldHld2').value = data.pldHld2;
  84. g('pldHld3').value = data.pldHld3;
  85. g('hld1ToRel').value = data.hld1ToRel;
  86. g('hld2ToRel').value = data.hld2ToRel;
  87. g('hld3ToRel').value = data.hld3ToRel;
  88. g('domIdx1').value = data.domIdx1;
  89. g('domIdx2').value = data.domIdx2;
  90. g('domIdx3').value = data.domIdx3;
  91. xhttp = null;
  92. reqFin = false;
  93. }
  94. else {
  95. if(!reqFin && reqTime > 10) {
  96. xhttp = null;
  97. reqFin = true;
  98. }
  99. }
  100. }
  101. }
  102. return false;
  103. }
  104. transmit();
  105. setInterval(function () { ++reqTime; }, 1000);
  106. </script>
  107. </body></html>