-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestBLE.js
More file actions
41 lines (30 loc) · 1.2 KB
/
testBLE.js
File metadata and controls
41 lines (30 loc) · 1.2 KB
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
const btSerial = new (require('bluetooth-serial-port')).BluetoothSerialPort();
console.log('Searching for Bluetooth devices...');
btSerial.on('found', function(address, name) {
console.log('Found: ' + address + ' Name: ' + name);
btSerial.findSerialPortChannel(address, function(channel) {
if (address === '00:06:66:DC:85:B7') {
btSerial.connect(address, channel, function() {
console.log('connected');
let buf = new Buffer(1);
buf.write("1", 0);
btSerial.write(buf, function(err, bytesWritten) {
if (err) console.log(err);
});
console.log('Buffer sent ' + buf);
btSerial.on('data', function(buffer) {
console.log('Recived: ' + buffer);
console.log(typeof buffer);
//console.log(buffer.toString('utf-8'));
});
}, function () {
console.log('cannot connect');
});
// close the connection when you're ready
btSerial.close();
}
}, function() {
console.log('found nothing');
});
});
btSerial.inquire();