-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClientBIT.html
60 lines (55 loc) · 2.04 KB
/
ClientBIT.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
<html>
<script language="javascript" type="text/javascript" src="jquery.js"></script>
<script language="javascript" type="text/javascript" src="jquery.flot.js"></script>
<script type="text/javascript">
var num_devices = 2
var ws = []
var all_data = []
for (i = 0; i<num_devices; i++){
// Establish a connection to the ServerBIT
var dev_id = i.toString()
ws.push( new WebSocket("ws://localhost:9001/"+dev_id) );
}
//for (i = 0; i<ws.length; i++){
// Process the responses sent by the ServerBIT
var i = 0
ws[i].onmessage = function (e) {
var data_stream = ""
data = JSON.parse(e.data)
var d1 = [];
orientation_labels = ["PITCH", "YAW", "ROLL", "HEAD"]
for (var l = 0; l < orientation_labels.length; l += 1){
ch = orientation_labels[l]
data_stream += ch + ": " + data[ch] + "<br />"
}
all_data[0] = (data_stream)
};
i=1
ws[i].onmessage = function (e) {
var data_stream = ""
data = JSON.parse(e.data)
var d1 = [];
orientation_labels = ["PITCH", "YAW", "ROLL", "HEAD"]
for (var l = 0; l < orientation_labels.length; l += 1){
ch = orientation_labels[l]
data_stream += ch + ": " + data[ch] + "<br />"
}
all_data[1] = (data_stream)
$("#data_stream").html(all_data[0] + "</br>" + all_data[1]);
};
// Detect when the page is unloaded or close
window.onbeforeunload = function() {
for (i = 0; i<num_devices; i++){
ws.onclose = function () {};
ws.close()
}
};
$("#data_stream").change(function() {
})
</script>
<body>
<div><h1>BITalino R-IoT WS (multiple devices)</h1></div>
<p id="data_stream">No data received</p>
<div id="placeholder" style="width:600px;height:300px;"></div>
</body>
</html>