conf.htm 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <h3>Configuration</h3>
  2. MQTT Server:
  3. <span id="mqtthost"></span>
  4. <br/> MQTT Port:
  5. <span id="mqttport"></span>
  6. <br/> MQTT User:
  7. <span id="mqttuser"></span>
  8. <br/> MQTT Password:
  9. <span id="mqttpass"></span>
  10. <h6>Last updated
  11. <span id="ut"></span> seconds ago.
  12. <span id="status"></span>
  13. </h6>
  14. <h3>Update Data</h3>
  15. <form id="xform" onsubmit="return transmit(this)">
  16. x:
  17. <input type="number" name="x" />
  18. <input type="submit" />
  19. </form>
  20. <form id="yform" onsubmit="return transmit(this)">
  21. y:
  22. <input type="text" name="y" />
  23. <input type="submit" />
  24. </form>
  25. <form id="zform" onsubmit="return transmit(this)">
  26. z:
  27. <input type="text" name="z" />
  28. <input type="submit" />
  29. </form>
  30. <a href="wifi.htm">WiFi settings</a>
  31. <script>
  32. function g(i) { return document.getElementById(i) };
  33. var xhttp, updateTime;
  34. function transmit(f) {
  35. if (!xhttp) { //prevent simultaneous requests
  36. g("status").innerHTML = "updating...";
  37. xhttp = new XMLHttpRequest();
  38. xhttp.open("POST", "/api");
  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. g("x").innerHTML = data.x;
  44. g("y").innerHTML = data.y;
  45. g("z").innerHTML = data.z;
  46. xhttp = null;
  47. g("status").innerHTML = "";
  48. updateTime = 0;
  49. }
  50. }
  51. }
  52. return false; //prevent form redirect
  53. }
  54. transmit();
  55. setInterval(function () { g("ut").innerHTML = ++updateTime; }, 1000);
  56. setInterval(transmit, 5000); //autoupdate display every 5s
  57. </script>