index.htm 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <h3>Current Data</h3>
  2. x:
  3. <span id="x"></span>
  4. <br/> y:
  5. <span id="y"></span>
  6. <br/> z:
  7. <span id="z"></span>
  8. <br/> current WiFi SSID:
  9. <span id="ssid"></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><br/>
  31. <a href="/update">Firmware Update</a>
  32. <script>
  33. function g(i) { return document.getElementById(i) };
  34. var xhttp, updateTime;
  35. function transmit(f) {
  36. if (!xhttp) { //prevent simultaneous requests
  37. g("status").innerHTML = "updating...";
  38. xhttp = new XMLHttpRequest();
  39. xhttp.open("POST", "/api");
  40. xhttp.send(f ? (new FormData(f)) : "");
  41. xhttp.onreadystatechange = function () {
  42. if (xhttp.readyState === XMLHttpRequest.DONE && xhttp.status === 200) {
  43. var data = JSON.parse(xhttp.responseText);
  44. g("x").innerHTML = data.x;
  45. g("y").innerHTML = data.y;
  46. g("z").innerHTML = data.z;
  47. g("ssid").innerHTML = data.ssid;
  48. xhttp = null;
  49. g("status").innerHTML = "";
  50. updateTime = 0;
  51. }
  52. }
  53. }
  54. return false; //prevent form redirect
  55. }
  56. transmit();
  57. setInterval(function () { g("ut").innerHTML = ++updateTime; }, 1000);
  58. setInterval(transmit, 5000); //autoupdate display every 5s
  59. </script>