Seperate webpage for the diagram

This commit is contained in:
Ollo 2021-12-18 13:41:51 +01:00
parent ae6c53d39b
commit a3be4f19a1
3 changed files with 42 additions and 31 deletions

37
data/chart.htm Normal file
View File

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>IKEA Home Sensor Diagram</title>
<script src="/chart.min.js"></script>
<script type="text/javascript">
function onBodyLoad(){
const xhttp = new XMLHttpRequest();
xhttp.responseType = 'json';
xhttp.onload = function() {
var jsonResponse = this.response;
console.log("JSON received");
const ctx = document.getElementById('myChart');
const myChart = new Chart(ctx, {
type: 'line',
data: jsonResponse,
options: {
scales: {
y: {
beginAtZero: false
}
}
}
});
console.log("Diagram generated");
}
xhttp.open("GET", "/diagram", true);
xhttp.send();
}
</script>
</head>
<body id="body" onload="onBodyLoad()">
<canvas id="myChart" width="100%" height="100"></canvas>
</body>
</html>

View File

@ -14,7 +14,6 @@
background-color: #b8b8b8; color: black;
}
</style>
<script src="/chart.min.js"></script>
<script type="text/javascript">
function mySensorTimer(){
const xhttp = new XMLHttpRequest();
@ -43,34 +42,6 @@
function onBodyLoad(){
setInterval(mySensorTimer, 5000);
// Test chart
const ctx = document.getElementById('myChart');
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)"
}
]
}
const myChart = new Chart(ctx, {
type: 'line',
data: dynamicData,
options: {
scales: {
y: {
beginAtZero: false
}
}
}
});
}
</script>
</head>
@ -117,6 +88,9 @@
</tr>
</tbody>
</table>
<canvas id="myChart" width="100%" height="100"></canvas>
<h1>Diagram</h1>
<p>
Can be found on the <a href="chart.htm">next page</a>.
</p>
</body>
</html>

View File

@ -25,4 +25,4 @@ lib_deps = https://github.com/homieiot/homie-esp8266.git#develop
adafruit/Adafruit BMP280 Library @ ^2.4.2
adafruit/Adafruit BME680 Library @ ^2.0.1
upload_port = /dev/ttyUSB0
upload_port = /dev/ttyUSB1