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>
|
2021-11-28 14:07:36 +01:00
|
|
|
<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>
|
2021-11-27 17:08:03 +01:00
|
|
|
<script type="text/javascript">
|
2021-11-28 14:07:36 +01:00
|
|
|
function mySensorTimer(){
|
2021-11-27 17:08:03 +01:00
|
|
|
const xhttp = new XMLHttpRequest();
|
2021-11-28 13:59:49 +01:00
|
|
|
xhttp.responseType = 'json';
|
2021-11-27 17:08:03 +01:00
|
|
|
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);
|
2021-11-27 17:08:03 +01:00
|
|
|
}
|
|
|
|
xhttp.open("GET", "/sensors", true);
|
|
|
|
xhttp.send();
|
|
|
|
}
|
2021-11-28 14:07:36 +01:00
|
|
|
|
|
|
|
function onBodyLoad(){
|
|
|
|
setInterval(mySensorTimer, 5000);
|
2021-12-16 20:21:24 +01:00
|
|
|
|
|
|
|
// Test chart
|
|
|
|
const ctx = document.getElementById('myChart');
|
2021-12-17 20:59:34 +01:00
|
|
|
dynamicData = {
|
|
|
|
labels: [ "0", "-30", "-60", "-90", "-120", "-160" ],
|
|
|
|
datasets: [{
|
|
|
|
label: 'temp',
|
|
|
|
data: [24, 22, 23, 25, 22, 23],
|
|
|
|
borderColor: "rgba(255,0,0,1)"
|
|
|
|
}, {
|
|
|
|
label: 'pressure',
|
|
|
|
data: [1000, 1002, 1003, 999, 996, 1000],
|
|
|
|
borderColor: "rgba(0,0,255,1)"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2021-12-16 20:21:24 +01:00
|
|
|
const myChart = new Chart(ctx, {
|
2021-12-16 20:40:44 +01:00
|
|
|
type: 'line',
|
2021-12-17 20:59:34 +01:00
|
|
|
data: dynamicData,
|
2021-12-16 20:21:24 +01:00
|
|
|
options: {
|
|
|
|
scales: {
|
|
|
|
y: {
|
2021-12-17 20:59:34 +01:00
|
|
|
beginAtZero: false
|
2021-12-16 20:21:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-11-28 14:07:36 +01:00
|
|
|
}
|
2021-11-27 17:08:03 +01:00
|
|
|
</script>
|
2021-11-27 16:19:35 +01:00
|
|
|
</head>
|
2021-11-27 17:08:03 +01:00
|
|
|
<body id="body" onload="onBodyLoad()">
|
2021-11-27 16:19:35 +01:00
|
|
|
<h1>Room Sensor</h1>
|
2021-11-27 17:08:03 +01:00
|
|
|
<table>
|
2021-11-28 13:59:49 +01:00
|
|
|
<thead>
|
2021-11-28 14:07:36 +01:00
|
|
|
<tr class="heading">
|
2021-11-27 17:08:03 +01:00
|
|
|
<td>Sensor</td>
|
|
|
|
<td>Value</td>
|
|
|
|
<td></td>
|
2021-11-28 13:59:49 +01:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2021-11-28 14:07:36 +01:00
|
|
|
<tr class="d0">
|
2021-11-27 17:08:03 +01:00
|
|
|
<td>Temperatur</td>
|
|
|
|
<td id="temp">temp</td>
|
|
|
|
<td>°C</td>
|
|
|
|
</tr>
|
2021-11-28 14:07:36 +01:00
|
|
|
<tr id="rowHumidity" class="d1">
|
2021-11-27 17:08:03 +01:00
|
|
|
<td>Humidity</td>
|
|
|
|
<td id="humidity">humidity</td>
|
|
|
|
<td>%</td>
|
|
|
|
</tr>
|
2021-11-28 14:07:36 +01:00
|
|
|
<tr id="rowGas" class="d0">
|
2021-11-27 17:08:03 +01:00
|
|
|
<td>Gas</td>
|
|
|
|
<td id="gas">gas</td>
|
|
|
|
<td> KOhms</td>
|
|
|
|
</tr>
|
2021-11-28 14:07:36 +01:00
|
|
|
<tr class="d1">
|
2021-11-27 17:08:03 +01:00
|
|
|
<td>Altitude</td>
|
|
|
|
<td id="altitude">altitude</td>
|
|
|
|
<td>m</td>
|
|
|
|
</tr>
|
2021-11-28 14:07:36 +01:00
|
|
|
<tr class="d0">
|
2021-11-27 17:08:03 +01:00
|
|
|
<td>Pressure</td>
|
|
|
|
<td id="pressure">pressure</td>
|
|
|
|
<td>hPa</td>
|
|
|
|
</tr>
|
2021-11-28 14:07:36 +01:00
|
|
|
<tr class="d1">
|
2021-11-27 17:08:03 +01:00
|
|
|
<td>Particle</td>
|
|
|
|
<td id="particle">particle</td>
|
|
|
|
<td>micro gram per quibik</td>
|
|
|
|
</tr>
|
2021-11-28 13:59:49 +01:00
|
|
|
</tbody>
|
2021-11-27 17:08:03 +01:00
|
|
|
</table>
|
2021-12-17 20:59:34 +01:00
|
|
|
<canvas id="myChart" width="100%" height="100"></canvas>
|
2021-11-27 16:19:35 +01:00
|
|
|
</body>
|
|
|
|
</html>
|