-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiotcity.js
52 lines (44 loc) · 1.3 KB
/
iotcity.js
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
var DEVICE_ID = 'F0:22:8C:55:F5:D3';
var redbear = {
serviceUUID: "713D0000-503E-4C75-BA94-3148F18D941E",
txCharacteristic: "713D0003-503E-4C75-BA94-3148F18D941E", // transmit is from the phone's perspective
rxCharacteristic: "713D0002-503E-4C75-BA94-3148F18D941E" // receive is from the phone's perspective
};
if(Meteor.isClient) {
Session.setDefault("connected", false);
ble.isEnabled(function() {
Session.set("enabled", true);
}, function() {
Session.set("enabled", false);
});
Template.hello.events({
'click #connect': function(event, template) {
event.preventDefault();
ble.scan([], 5,
function(peripherals){
connectDevice(DEVICE_ID);
},
function(){
console.log('No devices found');
});
}
});
Template.hello.helpers({
connected : function(value) {
return Session.get("connected") === value;
},
enabled: function() {
return Session.get("enabled");
}
});
}
var connectDevice = function (device_id) {
console.log("here");
ble.connect(device_id,
function(device){
Session.set('connected',true);
},
function(){
Session.set('connected',false);
});
};