forked from octoblu/meshblu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
62 lines (54 loc) · 1.69 KB
/
demo.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
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://skynet.im/js/skynet.js"></script>
<script>
$( document ).ready(function() {
$('#uuid').append(location.pathname.split("/")[2]);
});
var skynetConfig = {
// "uuid": location.pathname.split("/")[2],
// "token": location.pathname.split("/")[3]
"uuid": "1917e841-afb7-11e3-912d-bd75677ad63b",
"token": "xufbkulx6pkqpvidvzmh3qyra6mvx6r"
// "host": "localhost",
// "port": 3000
}
skynet(skynetConfig, function (e, socket, device) {
console.log(e);
if (e) throw e
console.log('REGISTERED', device);
// Send and receive messages
// socket.emit('message', {
// "devices": location.pathname.split("/")[2],
// "payload": {
// "skynet":"online"
// }}, function(data){
// console.log(data);
// });
// Subscribe to device/node i/o
socket.emit('subscribe', {
uuid: location.pathname.split("/")[2]
},
function(data){
console.log(data);
});
socket.on('message', function(message){
// console.log('message received', channel, message);
if(typeof message == "string"){
message = JSON.parse(message);
}
if(message && message.payload.x !== undefined){
$('#device').html("X Axis : " + message.payload.x + " Y Axis : " + message.payload.y);
}
});
});
</script>
</head>
<body>
<p>Connecting to SkyNet!</p>
<p>Subscribing to UUID: <span id="uuid"></span></p>
<p>Listening for sensor data...</p>
<div id="device"></div>
</body>
</html>