HomieRoomSensor/data/index.htm

133 lines
4.0 KiB
HTML
Raw Normal View History

2021-11-27 16:19:35 +01:00
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>IKEA Home Sensor</title>
<style type="text/css">
tr.heading td {
background-color: black; color: white;
}
tr.d0 td {
background-color: #ffffff; color: black;
}
tr.d1 td {
background-color: #b8b8b8; color: black;
}
</style>
2021-12-16 20:21:24 +01:00
<script src="/chart.min.js"></script>
<script type="text/javascript">
function mySensorTimer(){
const xhttp = new XMLHttpRequest();
2021-11-28 13:59:49 +01:00
xhttp.responseType = 'json';
xhttp.onload = function() {
2021-11-28 13:59:49 +01:00
var jsonResponse = this.response;
document.getElementById("temp").innerHTML = jsonResponse.temp
document.getElementById("altitude").innerHTML = jsonResponse.altitude;
document.getElementById("pressure").innerHTML = jsonResponse.pressure;
document.getElementById("particle").innerHTML = jsonResponse.particle;
if (jsonResponse.gas) {
document.getElementById("gas").innerHTML = jsonResponse.gas;
} else {
document.getElementById("rowGas").hidden = true;
}
if (jsonResponse.humidity) {
document.getElementById("humidity").innerHTML = jsonResponse.humidity;
} else {
document.getElementById("rowHumidity").hidden = true;
}
console.log(this.responseText);
}
xhttp.open("GET", "/sensors", true);
xhttp.send();
}
function onBodyLoad(){
setInterval(mySensorTimer, 5000);
2021-12-16 20:21:24 +01:00
// Test chart
const ctx = document.getElementById('myChart');
const myChart = new Chart(ctx, {
type: 'line',
2021-12-16 20:21:24 +01:00
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
}
</script>
2021-11-27 16:19:35 +01:00
</head>
<body id="body" onload="onBodyLoad()">
2021-11-27 16:19:35 +01:00
<h1>Room Sensor</h1>
<table>
2021-11-28 13:59:49 +01:00
<thead>
<tr class="heading">
<td>Sensor</td>
<td>Value</td>
<td></td>
2021-11-28 13:59:49 +01:00
</tr>
</thead>
<tbody>
<tr class="d0">
<td>Temperatur</td>
<td id="temp">temp</td>
<td>°C</td>
</tr>
<tr id="rowHumidity" class="d1">
<td>Humidity</td>
<td id="humidity">humidity</td>
<td>%</td>
</tr>
<tr id="rowGas" class="d0">
<td>Gas</td>
<td id="gas">gas</td>
<td> KOhms</td>
</tr>
<tr class="d1">
<td>Altitude</td>
<td id="altitude">altitude</td>
<td>m</td>
</tr>
<tr class="d0">
<td>Pressure</td>
<td id="pressure">pressure</td>
<td>hPa</td>
</tr>
<tr class="d1">
<td>Particle</td>
<td id="particle">particle</td>
<td>micro gram per quibik</td>
</tr>
2021-11-28 13:59:49 +01:00
</tbody>
</table>
<canvas id="myChart" width="100%" height="400"></canvas>
2021-11-27 16:19:35 +01:00
</body>
</html>