This repository has been archived by the owner on Feb 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
69 lines (61 loc) · 1.52 KB
/
test.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
69
<html>
<head>
</head>
<body>
<script src="https://www.puck-js.com/puck.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.min.js"></script>
<script type="application/javascript" src="/home/pi/~/influxdb.min.js"></script>
<button onclick="Puck.write("\x10sendData()\n");">On!</button>
<button onclick="Puck.write('LED1.reset();\n');">Off!</button>
<button id="myBtn">Try it</button>
<script>
var myData = [];
var i = 0;
/*
influxdb = new InfluxDB({
"host" :"localhost",
"port" :"8086",
"username" :"",
"password" :"",
"database" :"ruuvi"
});
*/
influxdb = new Influxdb('http://localhost:8086/write?db=ruuvi',true);
console.log("Starting")
function onLine(data) {
// influxdb.writePoint("acc", data);
//console.log(data);
}
var connection;
document.getElementById("myBtn").addEventListener("click", function() {
myData = [];
i = 0;
if (connection) {
connection.close();
connection = undefined;
}
Puck.connect(function(c) {
if (!c) {
alert("Couldn't connect!");
return;
}
connection = c;
// Handle the data we get back, and call 'onLine'
// whenever we get a line
var buf = "";
connection.on("data", function(d) {
buf += d;
var i = buf.indexOf("\n");
while (i>=0) {
onLine(buf.substr(0,i));
buf = buf.substr(i+1);
i = buf.indexOf("\n");
}
});
// Request data from Puck.js
connection.write("\x10sendData()\n");
});
});
</script>
</body>
</html>