-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
68 lines (59 loc) · 1.71 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script
type="text/javascript"
src="https://www.google.com/jsapi?autoload={
'modules':[{
'name':'visualization',
'version':'1',
'packages':['corechart']
}]
}"
></script>
</head>
<body>
<div id="chart" style="width: 900px; height: 500px"></div>
<script type="text/javascript">
$(document).ready(function() {
var maxDataPoints = 10;
var chart = new google.visualization.LineChart($("#chart")[0]);
var data = google.visualization.arrayToDataTable([
["Time", "Temperature"],
[getTime(), 0]
]);
var options = {
title: "Temperature",
curveType: "function",
animation: {
duration: 1000,
easing: "in"
},
legend: { position: "bottom" }
};
function addDataPoint(dataPoint) {
if (data.getNumberOfRows() > maxDataPoints) {
data.removeRow(0);
}
data.addRow([getTime(), dataPoint.value]);
chart.draw(data, options);
}
function getTime() {
var d = new Date();
return d.toLocaleTimeString();
}
var socket = new WebSocket(
"ws://devices.webofthings.io/pi/sensors/temperature"
);
socket.onmessage = function(event) {
var result = JSON.parse(event.data);
addDataPoint(result);
};
socket.onerror = function(error) {
console.log("WebSocket error!");
console.log(error);
};
});
</script>
</body>
</html>