Advertisement
Guest User

Untitled

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