forked from sandeepmistry/node-core-bluetooth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-peripheral.js
86 lines (75 loc) · 2.13 KB
/
test-peripheral.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var CoreBluetooth = require('./index');
var PeripheralManager = CoreBluetooth.PeripheralManager;
var MutableService = CoreBluetooth.MutableService;
var MutableCharacteristic = CoreBluetooth.MutableCharacteristic;
var MutableDescriptor = CoreBluetooth.MutableDescriptor;
var peripheralManager = new PeripheralManager();
peripheralManager.on('address', function(address) {
console.log('\taddress => ', address);
});
peripheralManager.on('stateUpdate', function(state) {
console.log('\tstateUpdate => ', state);
console.log('startAdvertising');
peripheralManager.startAdvertising({
localName: 'test',
serviceUuids: ['FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFF0']
});
});
peripheralManager.on('advertisingStart', function(error) {
console.log('\tadvertisingStart => ', error);
var service = new MutableService(
'FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFF0',
true,
[],
[
new MutableCharacteristic(
'FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFF1',
0x02,
new Buffer('static value'),
0x01,
[
new MutableDescriptor('2901', 'static read')
]
),
new MutableCharacteristic(
'FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFF2',
0x02,
null,
0x01,
[]
),
new MutableCharacteristic(
'FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFF3',
0x08,
null,
0x02,
[]
),
new MutableCharacteristic(
'FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFF4',
0x04,
null,
0x02,
[]
),
new MutableCharacteristic(
'FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFF4',
0x10,
null,
0x01,
[]
)
]
);
console.log('addService');
peripheralManager.addService(service);
});
peripheralManager.on('serviceAdded', function(service, error) {
console.log('\tserviceAdded =>', JSON.stringify(service, null, 2), error);
});
peripheralManager.on('accept', function(centralIdentifier, address) {
console.log('\taccept => ', centralIdentifier, address);
});
peripheralManager.on('mtuChange', function(mtu) {
console.log('\tmtuChange => ', mtu);
});