-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
executable file
·51 lines (41 loc) · 1.38 KB
/
main.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
let bleno = require('bleno');
let characteristicsPM5 = require('./characteristicPM531');
var socket = require('./socketController')(characteristicsPM5);
let PM5Util = require('./PM5Util');
// return;
PM5Util.setSocketController(socket);
var BlenoPrimaryService = bleno.PrimaryService;
// var uuidErgService = PM5Util.toLongUUID("0030")//'18902a9a-1f4a-44fe-936f-14c8eea41800';// '6969';
console.log('PM5 bleno - simulation');
bleno.on('stateChange', function(state) {
console.log('on -> stateChange: ' + state);
if (state === 'poweredOn') {
bleno.startAdvertising('PM5', ['ec00']);
} else {
bleno.stopAdvertising();
}
});
bleno.on('advertisingStart', function(error) {
console.log('on -> advertisingStart: ' + (error ? 'error ' + error : 'success'));
// console.log(characteristicsPM5.characteristics);
if (!error) {
bleno.setServices([
new BlenoPrimaryService({
uuid: PM5Util.toLongUUID("0030"),
characteristics: characteristicsPM5.characteristics[0]
}),
new BlenoPrimaryService({
uuid: PM5Util.toLongUUID("0130"),
characteristics: characteristicsPM5.characteristics[1]
}),
new BlenoPrimaryService({
uuid: PM5Util.toLongUUID("0230"),
characteristics: characteristicsPM5.characteristics[2]
}),
new BlenoPrimaryService({
uuid: PM5Util.toLongUUID("0330"),
characteristics: characteristicsPM5.characteristics[3]
})
]);
}
});