forked from jpoles1/berrymed-pulseox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (24 loc) · 925 Bytes
/
index.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
const bluetooth = require('node-bluetooth');
// create bluetooth device instance
const device = new bluetooth.DeviceINQ();
device
.on('finished', console.log.bind(console, 'finished'))
.on('found', function found(address, name){
console.log('Found: ' + address + ' with name ' + name);
// find serial port channel
device.findSerialPortChannel(address, function(channel){
console.log('Found RFCOMM channel for serial port on %s: ', name, channel);
// make bluetooth connect to remote device
bluetooth.connect(address, channel, function(err, connection){
if(err) return console.error(err);
connection.delimiter = Buffer.from('\n', 'utf8');
connection.on('data', (buffer) => {
console.log('received message:', buffer.toString());
});
connection.write(new Buffer('Hello!', 'utf-8'), () => {
console.log('wrote');
});
});
});
})
device.scan();