html_confmqtt.ino 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. static const char html_confmqtt_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. updCbxVal(g('mqttEnable'));
  29. updCbxVal(g('outRet'));
  30. updCbxVal(g('willRet'));
  31. updCbxVal(g('hbEnable'));
  32. xhttp = new XMLHttpRequest();
  33. xhttp.timeout = 1000;
  34. xhttp.overrideMimeType('application/json');
  35. xhttp.open('POST', 'confdmqtt');
  36. xhttp.send(f ? (new FormData(f)) : '');
  37. xhttp.onreadystatechange = function () {
  38. if (xhttp.readyState === XMLHttpRequest.DONE && xhttp.status === 200) {
  39. var data = JSON.parse(xhttp.responseText);
  40. setCbx(g('mqttEnable'), data.mqttEnable);
  41. g('mqttHost').value = data.mqttHost;
  42. g('mqttPort').value = data.mqttPort;
  43. g('mqttUser').value = data.mqttUser;
  44. g('inTop').value = data.inTop;
  45. g('outTop').value = data.outTop;
  46. g('willTop').value = data.willTop;
  47. g('willQos').value = data.willQos;
  48. setCbx(g('outRet'), data.outRet);
  49. setCbx(g('willRet'), data.willRet);
  50. g('willMsg').value = data.willMsg;
  51. g('connMsg').value = data.connMsg;
  52. setCbx(g('hbEnable'), data.hbEnable);
  53. g('hbReconn').value = data.hbReconn;
  54. g('hbReboot').value = data.hbReboot;
  55. xhttp = null;
  56. reqFin = true;
  57. }
  58. else {
  59. if(!reqFin && reqTime > 10) {
  60. xhttp = null;
  61. reqFin = true;
  62. }
  63. }
  64. }
  65. }
  66. return false;
  67. }
  68. //transmit();
  69. function saveConf() {
  70. updCbxVal(g('mqttEnable'));
  71. updCbxVal(g('outRet'));
  72. updCbxVal(g('willRet'));
  73. updCbxVal(g('hbEnable'));
  74. g('frmConf').submit();
  75. }
  76. function init() {
  77. transmit();
  78. setCbx(g('mqttPassSet'), 0);
  79. }
  80. setInterval(function () { ++reqTime; }, 1000);
  81. </script>
  82. )====="; // html_confmqtt_script
  83. static const char html_confmqtt_body[] PROGMEM = R"=====(
  84. <b>Configuration - MQTT</b>
  85. <div class='config'>
  86. <form id='frmConf' action='setConfMqtt' method='POST'>
  87. <br>
  88. <p><b>Enable MQTT *</b>&nbsp;<input type='checkbox' name='mqttEnable' id='mqttEnable'></p>
  89. <fieldset>
  90. <legend>Broker Connection</legend>
  91. <p><b>Hostname *</b><br><input type='text' name='mqttHost' id='mqttHost'></p>
  92. <p><b>Port *</b><br><input type='number' name='mqttPort' id='mqttPort'></p>
  93. <p><b>User *</b><br><input type='text' name='mqttUser' id='mqttUser'></p>
  94. <p><b>Password *</b><input type='checkbox' id='mqttPassSet' name='mqttPassSet' onclick='sp("mqttPass")'><br><input type='password' name='mqttPass' id='mqttPass'></p>
  95. </fieldset>
  96. <br>
  97. <fieldset>
  98. <legend>Last Will</legend>
  99. <p><b>Topic *</b><br><input type='text' name='willTop' id='willTop'></p>
  100. <p><b>Qos *</b><br><select name='willQos' id='willQos'><option>0</option><option>1</option><option selected='selected'>2</option></select></p>
  101. <p><b>Retain-Flag *</b>&nbsp;<input type='checkbox' name='willRet' id='willRet'></p>
  102. <p><b>Last Will Message *</b><br><input type='text' name='willMsg' id='willMsg'></p>
  103. <p><b>Connect Message *</b><br><input type='text' name='connMsg' id='connMsg'></p>
  104. </fieldset>
  105. <br>
  106. <fieldset>
  107. <legend>Base Topics</legend>
  108. <p><b>In/Command *</b><br><input type='text' name='inTop' id='inTop'></p>
  109. <div></div>
  110. <p><b>Out/State</b><br><input type='text' name='outTop' id='outTop'></p>
  111. <p><b>Retain-Flag *</b>&nbsp;<input type='checkbox' name='outRet' id='outRet'></p>
  112. </fieldset>
  113. <br>
  114. <fieldset>
  115. <legend>Heartbeat</legend>
  116. <p><b>Enable Heartbeat *</b>&nbsp;<input type='checkbox' name='hbEnable' id='hbEnable'></p>
  117. <div></div>
  118. <p class='p'>on missing Heartbeat:</p>
  119. <br><br><div></div>
  120. <p><b>Reconnect after [min]</b><br><input type='text' name='hbReconn' id='hbReconn'></p>
  121. <p><b>Reboot after [min]</b><br><input type='text' name='hbReboot' id='hbReboot'></p>
  122. </fieldset>
  123. <div></div>
  124. </form>
  125. <div></div>
  126. <table style='width:100%'>
  127. <td style='width:50%'><button onclick='location="conf";' class='bgrey'>Cancel</button></td>
  128. <td style='width:50%'><button onclick='return saveConf()' class='bred'>Save</button></td>
  129. </tr></table>
  130. </div>
  131. )====="; // html_confmqtt_body