html_confMqtt.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /* clang-format off */
  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. static const char html_confmqtt_script[] PROGMEM = R"=====(
  25. function transmit(f) {
  26. if (!xhttp) {
  27. reqTime = 0;
  28. reqFin = false;
  29. updCbxVal(g('mqttEnable'));
  30. updCbxVal(g('outRet'));
  31. updCbxVal(g('outRetSens'));
  32. updCbxVal(g('willRet'));
  33. updCbxVal(g('hbEnable'));
  34. updCbxVal(g('reconSilent'));
  35. xhttp = new XMLHttpRequest();
  36. xhttp.timeout = 1000;
  37. xhttp.overrideMimeType('application/json');
  38. xhttp.open('POST', 'confDataMqtt');
  39. xhttp.send(f ? (new FormData(f)) : '');
  40. xhttp.onreadystatechange = function () {
  41. if (xhttp.readyState === XMLHttpRequest.DONE && xhttp.status === 200) {
  42. var data = JSON.parse(xhttp.responseText);
  43. setCbx(g('mqttEnable'), data.mqttEnable);
  44. g('mqttHost').value = data.mqttHost;
  45. g('mqttPort').value = data.mqttPort;
  46. g('mqttUser').value = data.mqttUser;
  47. g('mqttPass').value = data.mqttPass;
  48. g('inTop').value = data.inTop;
  49. g('outTop').value = data.outTop;
  50. g('willTop').value = data.willTop;
  51. g('willQos').value = data.willQos;
  52. setCbx(g('outRet'), data.outRet);
  53. setCbx(g('outRetSens'), data.outRetSens);
  54. g('outPubInt').value = data.outPubInt;
  55. g('outPubIntSens').value = data.outPubIntSens;
  56. setCbx(g('willRet'), data.willRet);
  57. g('willMsg').value = data.willMsg;
  58. g('connMsg').value = data.connMsg;
  59. setCbx(g('hbEnable'), data.hbEnable);
  60. g('hbReconn').value = data.hbReconn;
  61. g('hbReboot').value = data.hbReboot;
  62. setCbx(g('reconSilent'), data.reconSilent);
  63. xhttp = null;
  64. reqFin = true;
  65. }
  66. else {
  67. if(!reqFin && reqTime > 10) {
  68. xhttp = null;
  69. reqFin = true;
  70. }
  71. }
  72. }
  73. }
  74. return false;
  75. }
  76. //transmit();
  77. function saveConf() {
  78. updCbxVal(g('mqttEnable'));
  79. updCbxVal(g('outRet'));
  80. updCbxVal(g('outRetSens'));
  81. updCbxVal(g('willRet'));
  82. updCbxVal(g('hbEnable'));
  83. updCbxVal(g('reconSilent'));
  84. g('frmConf').submit();
  85. }
  86. function init() {
  87. transmit();
  88. setCbx(g('mqttPassSet'), 0);
  89. }
  90. )====="; // html_confmqtt_script
  91. // setInterval(function () { ++reqTime; }, 1000);
  92. //</script>
  93. static const char html_confmqtt_body[] PROGMEM = R"=====(
  94. <b>Configuration - MQTT</b>
  95. <div class='config'>
  96. <form id='frmConf' action='setConfMqtt' method='POST'>
  97. <br>
  98. <p><b>Enable MQTT *</b>&nbsp;<input type='checkbox' name='mqttEnable' id='mqttEnable'></p>
  99. <fieldset>
  100. <legend>Broker Connection</legend>
  101. <p><b>Hostname *</b><br><input type='text' name='mqttHost' id='mqttHost'></p>
  102. <p><b>Port *</b><br><input type='number' name='mqttPort' id='mqttPort'></p>
  103. <p><b>User *</b><br><input type='text' name='mqttUser' id='mqttUser'></p>
  104. <p><b>Password *</b><input type='checkbox' id='mqttPassSet' name='mqttPassSet' onclick='sp("mqttPass")'><br><input type='password' name='mqttPass' id='mqttPass'></p>
  105. </fieldset>
  106. <br>
  107. <fieldset>
  108. <legend>Last Will</legend>
  109. <p><b>Topic *</b><br><input type='text' name='willTop' id='willTop'></p>
  110. <p><b>Qos *</b><br><select name='willQos' id='willQos'><option>0</option><option>1</option><option selected='selected'>2</option></select></p>
  111. <p><b>Retain-Flag *</b>&nbsp;<input type='checkbox' name='willRet' id='willRet'></p>
  112. <p><b>Last Will Message *</b><br><input type='text' name='willMsg' id='willMsg'></p>
  113. <p><b>Connect Message *</b><br><input type='text' name='connMsg' id='connMsg'></p>
  114. </fieldset>
  115. <br>
  116. <fieldset>
  117. <legend>Base Topics</legend>
  118. <p><b>Base In-Topic *</b><br><input type='text' name='inTop' id='inTop'></p>
  119. <p class='n'>* Sub-Topics like cmd... are added automatically.</p>
  120. <div></div>
  121. <p><b>Out/State-Topic **</b><br><input type='text' name='outTop' id='outTop'></p>
  122. <p class='n'>** default output topic. Sub-Topics are added automatically.</p>
  123. <p><b>Retain (States) *</b>&nbsp;<input type='checkbox' name='outRet' id='outRet'></p>
  124. <p><b>Retain (Sensors) *</b>&nbsp;<input type='checkbox' name='outRetSens' id='outRetSens'></p>
  125. <p class='n'>* If Retain is enabled, data is only sent on change, <br>
  126. otherwise in intervals additionally. <br>
  127. Intervals can also be switched off without retain. <br>
  128. Just set them to 0 to disable.</p>
  129. <p><b>Interval States [min]**</b><br><input type='number' name='outPubInt' id='outPubInt'></p>
  130. <p><b>Interval Sensors [min]**</b><br><input type='number' name='outPubIntSens' id='outPubIntSens'></p>
  131. <p class='n'>** 0 to disable</p>
  132. </fieldset>
  133. <br>
  134. <fieldset>
  135. <legend>Heartbeat</legend>
  136. <p><b>Enable Heartbeat *</b>&nbsp;<input type='checkbox' name='hbEnable' id='hbEnable'></p>
  137. <div></div><div></div>
  138. <p class='n'>on missing Heartbeat:</p>
  139. <p><b>Reconnect after [min]**</b><br><input type='text' name='hbReconn' id='hbReconn'></p>
  140. <p><b>Reboot after [min]**</b><br><input type='text' name='hbReboot' id='hbReboot'></p>
  141. <p><b>Reconnect silent *</b>&nbsp;<input type='checkbox' name='reconSilent' id='reconSilent'></p>
  142. <p class='n'>* do not show reconnect on LCD</p>
  143. <p class='n'>** 0 to disable</p>
  144. </fieldset>
  145. <div></div>
  146. </form>
  147. <div></div>
  148. <table style='width:100%'>
  149. <td style='width:50%'><button onclick='location="conf";' class='bgrey'>Cancel</button></td>
  150. <td style='width:50%'><button onclick='return saveConf()' class='bred'>Save</button></td>
  151. </tr></table>
  152. </div>
  153. )====="; // html_confmqtt_body