Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  //FETCH OTA STATUS
  2.       setInterval(function ( ) {
  3.       var xhttp = new XMLHttpRequest();
  4.       xhttp.onreadystatechange = function() {
  5.         if (this.readyState == 4 && this.status == 200) {
  6.           document.getElementById("ota_status").innerHTML = xhttp.responseText;
  7.         }
  8.       };
  9.       xhttp.open("GET", "/OTA_Status", true);
  10.       xhttp.send();
  11.       }, interval );
  12.  
  13.       //FETCH MQTT STATUS
  14.       setInterval(function ( ) {
  15.       var xhttp = new XMLHttpRequest();
  16.       xhttp.onreadystatechange = function() {
  17.         if (this.readyState == 4 && this.status == 200) {
  18.           document.getElementById("mqtt_status").innerHTML = xhttp.responseText;
  19.         }
  20.       };
  21.       xhttp.open("GET", "/MQTT_Status", true);
  22.       xhttp.send();
  23.     }, interval );
  24.  
  25.       var interval = 1000;
  26.       var kwh_price = 0.1587;
  27.  
  28.       document.getElementById("input_interval").placeholder = interval;
  29.       document.getElementById("kwh_price").placeholder = kwh_price;
  30.  
  31.       //Chart Clock timezone
  32.       Highcharts.setOptions({
  33.         global: {
  34.           useUTC: false
  35.         }
  36.       });
  37.  
  38.       //Chart Configs
  39.       var chartT = new Highcharts.Chart({
  40.         chart:{
  41.           renderTo : 'chart-current'
  42.         },
  43.         title: {
  44.            text: ''
  45.         },
  46.         series: [{
  47.           showInLegend: false,
  48.           data: []
  49.         }],
  50.         plotOptions: {
  51.           line: { animation: true,
  52.             dataLabels: { enabled: true }
  53.           },
  54.           series: { color: '#0066ff' }
  55.         },
  56.         xAxis: { type: 'datetime',
  57.           dateTimeLabelFormats: { second: '%H:%M:%S' }
  58.         },
  59.         yAxis: {
  60.           title: { text: 'Power (Watts)' }
  61.         },
  62.         credits: { enabled: false }
  63.       });
  64.      
  65.       //Update Values
  66.       setInterval(function ( ) {
  67.         var xhttp = new XMLHttpRequest();
  68.         xhttp.onreadystatechange = function() {
  69.           if (this.readyState == 4 && this.status == 200) {
  70.  
  71.             //Update Chart
  72.             var x = (new Date()).getTime(),
  73.                 y = parseFloat(this.responseText);
  74.             if(chartT.series[0].data.length > 40) {
  75.               chartT.series[0].addPoint([x, y], true, true, true);
  76.             } else {
  77.               chartT.series[0].addPoint([x, y], true, false, true);
  78.             }
  79.  
  80.             document.getElementById("power").innerHTML = this.responseText + "W";
  81.           }
  82.         };
  83.         xhttp.open("GET", "/POWER", true);
  84.         xhttp.send();
  85.       }, interval );
  86.  
  87.       setInterval(function ( ) {
  88.         var xhttp = new XMLHttpRequest();
  89.         xhttp.onreadystatechange = function() {
  90.           if (this.readyState == 4 && this.status == 200) {
  91.             document.getElementById("voltage").innerHTML = this.responseText + "V";
  92.           }
  93.         };
  94.         xhttp.open("GET", "/VOLTAGE", true);
  95.         xhttp.send();
  96.       }, interval ) ;
  97.       setInterval(function ( ) {
  98.         var xhttp = new XMLHttpRequest();
  99.         xhttp.onreadystatechange = function() {
  100.           if (this.readyState == 4 && this.status == 200) {
  101.             document.getElementById("current").innerHTML = this.responseText + "A";
  102.           }
  103.         };
  104.         xhttp.open("GET", "/CURRENT", true);
  105.         xhttp.send();
  106.       }, interval ) ;
  107.  
  108.       setInterval(function ( ) {
  109.         var xhttp = new XMLHttpRequest();
  110.         xhttp.onreadystatechange = function() {
  111.           if (this.readyState == 4 && this.status == 200) {
  112.             document.getElementById("energy").innerHTML = this.responseText  + "KWh";
  113.           }
  114.          
  115.         };
  116.         xhttp.open("GET", "/ENERGY", true);
  117.         xhttp.send();
  118.       }, interval ) ;
  119.  
  120.       setInterval(function ( ) {
  121.         var xhttp = new XMLHttpRequest();
  122.         xhttp.onreadystatechange = function() {
  123.           if (this.readyState == 4 && this.status == 200) {
  124.             document.getElementById("frequency").innerHTML = this.responseText + "Hz";
  125.           }
  126.         };
  127.         xhttp.open("GET", "/FREQUENCY", true);
  128.         xhttp.send();
  129.       }, interval ) ;
  130.  
  131.       setInterval(function ( ) {
  132.         var xhttp = new XMLHttpRequest();
  133.         xhttp.onreadystatechange = function() {
  134.           if (this.readyState == 4 && this.status == 200) {
  135.             document.getElementById("pf").innerHTML = this.responseText;
  136.           }
  137.         };
  138.         xhttp.open("GET", "/PF", true);
  139.         xhttp.send();
  140.       }, interval ) ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement