This repository was archived by the owner on Apr 9, 2021. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
92 lines (81 loc) · 2 KB
/
Copy pathindex.html
File metadata and controls
92 lines (81 loc) · 2 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!doctype html>
<html lang="en">
<head>
</head>
<body>
<p1 id ="candata" >data goes here</p1>
<div id="future"></div>
<script src="/jquery/dist/jquery.js"></script>
<script src = "/socket.io-client/dist/socket.io.js"></script>
<script type="text/javascript" src="canvasjs.min.js"></script>
</body>
<script>
//chart
window.onload = function () {
var dps = []; //dataPoints.
var chart = new CanvasJS.Chart("chartContainer",{
title :{
text: "Live Data"
},
axisX: {
title: "Axis X Title"
},
axisY: {
title: "Units"
},
data: [{
type: "line",
dataPoints : dps
}]
});
chart.render();
var xVal = dps.length + 1;
var yVal = 15;
var updateInterval = 1;
var updateChart = function () {
yVal = 0;
dps.push({x: xVal,y: yVal});
xVal++;
if (dps.length > 1000 ) {
dps.shift();
}
chart.render();
// update chart after specified time.
};
setInterval(function(){updateChart()}, updateInterval);
}
//IDs
const PEDALBOX2 = '501';
//socket
var socket = io.connect('http://192.168.42.1:5000');
socket.on('connect', function(data) {
socket.emit('join', 'Hello World from client');
});
socket.on('gotcandata', (data) => {
var s = ab2str(data);
var n = s[3];
if(s.substr(0, 2) == PEDALBOX2)
{
// updateChart();
document.getElementById("candata").innerHTML = s;
}
//file write
//fs.appendFile(s.substr(0,2) + ".txt", parswInt(s.substr(4, n*2)) + "\n");
});
//functions go here
function bin2String(array) {
var result = "";
for (var i = 0; i < array.length; i++) {
result += String.fromCharCode(parseInt(array[i], 8));
}
return result;
}
function ab2str(buf) {
return String.fromCharCode.apply(null, new Uint8Array(buf));
}
</script>
<body>
<div id="chartContainer" style="height: 300px; width: 100%;">
</div>
</body>
</html>