index.htm 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <!--
  2. FSWebServer - Example Index Page
  3. Copyright (c) 2015 Hristo Gochkov. All rights reserved.
  4. This file is part of the WebServer library for Arduino environment.
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. -->
  17. <!DOCTYPE html>
  18. <html>
  19. <head>
  20. <meta http-equiv="Content-type" content="text/html; charset=utf-8">
  21. <title>ESP Monitor</title>
  22. <script type="text/javascript" src="graphs.js"></script>
  23. <script type="text/javascript">
  24. var heap,temp,digi;
  25. var reloadPeriod = 1000;
  26. var running = false;
  27. function loadValues(){
  28. if(!running) return;
  29. var xh = new XMLHttpRequest();
  30. xh.onreadystatechange = function(){
  31. if (xh.readyState == 4){
  32. if(xh.status == 200) {
  33. var res = JSON.parse(xh.responseText);
  34. heap.add(res.heap);
  35. temp.add(res.analog);
  36. digi.add(res.gpio);
  37. if(running) setTimeout(loadValues, reloadPeriod);
  38. } else running = false;
  39. }
  40. };
  41. xh.open("GET", "/all", true);
  42. xh.send(null);
  43. };
  44. function run(){
  45. if(!running){
  46. running = true;
  47. loadValues();
  48. }
  49. }
  50. function onBodyLoad(){
  51. var refreshInput = document.getElementById("refresh-rate");
  52. refreshInput.value = reloadPeriod;
  53. refreshInput.onchange = function(e){
  54. var value = parseInt(e.target.value);
  55. reloadPeriod = (value > 0)?value:0;
  56. e.target.value = reloadPeriod;
  57. }
  58. var stopButton = document.getElementById("stop-button");
  59. stopButton.onclick = function(e){
  60. running = false;
  61. }
  62. var startButton = document.getElementById("start-button");
  63. startButton.onclick = function(e){
  64. run();
  65. }
  66. // Example with 10K thermistor
  67. //function calcThermistor(v) {
  68. // var t = Math.log(((10230000 / v) - 10000));
  69. // t = (1/(0.001129148+(0.000234125*t)+(0.0000000876741*t*t*t)))-273.15;
  70. // return (t>120)?0:Math.round(t*10)/10;
  71. //}
  72. //temp = createGraph(document.getElementById("analog"), "Temperature", 100, 128, 10, 40, false, "cyan", calcThermistor);
  73. temp = createGraph(document.getElementById("analog"), "Analog Input", 100, 128, 0, 1023, false, "cyan");
  74. heap = createGraph(document.getElementById("heap"), "Current Heap", 100, 125, 0, 30000, true, "orange");
  75. digi = createDigiGraph(document.getElementById("digital"), "GPIO", 100, 146, [0, 4, 5, 16], "gold");
  76. run();
  77. }
  78. </script>
  79. </head>
  80. <body id="index" style="margin:0; padding:0;" onload="onBodyLoad()">
  81. <div id="controls" style="display: block; border: 1px solid rgb(68, 68, 68); padding: 5px; margin: 5px; width: 362px; background-color: rgb(238, 238, 238);">
  82. <label>Period (ms):</label>
  83. <input type="number" id="refresh-rate"/>
  84. <input type="button" id="start-button" value="Start"/>
  85. <input type="button" id="stop-button" value="Stop"/>
  86. </div>
  87. <div id="heap"></div>
  88. <div id="analog"></div>
  89. <div id="digital"></div>
  90. </body>
  91. </html>