PowerAnalyzer/data/js/poll.js
Carsten Schmiemann f4a22880fe Initial Commit
2018-08-29 00:22:45 +02:00

22 lines
No EOL
914 B
JavaScript

function updateData() {
console.log("Fetching Data from ESP...");
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log("Data:", this.responseText);
var values = JSON.parse(this.responseText);
document.getElementById("voltage").innerHTML = values.voltage;
document.getElementById("current").innerHTML = values.current;
document.getElementById("power").innerHTML = values.power;
document.getElementById("Ah").innerHTML = values.Ah;
document.getElementById("Wh").innerHTML = values.Wh;
document.getElementById("battery").innerHTML = values.battery;
document.getElementById("run").innerHTML = values.run;
}
};
xhttp.open("GET", "/meas/values", true);
xhttp.send();
}
updateData();
window.setInterval(updateData, 3000);