Skip to content

Instantly share code, notes, and snippets.

@SoftwareDreamer
Created October 17, 2014 10:36
Show Gist options
  • Save SoftwareDreamer/e58a5cea52f81ef6afbe to your computer and use it in GitHub Desktop.
Save SoftwareDreamer/e58a5cea52f81ef6afbe to your computer and use it in GitHub Desktop.
devopenspace2014 connected devices nodejs example
// code by Martin Schmid
// see https://github.com/eelcocramer/node-bluetooth-serial-port#pre-requests-on-linux
// for OS specific requirements for Linux/Windows/OS X to access Bluetooth
var btSerial = new (require('bluetooth-serial-port')).BluetoothSerialPort();
btSerial.on('found', function(address, name) {
if (address === '00:13:EF:D6:53:6C') {
btSerial.findSerialPortChannel(address, function(channel) {
btSerial.connect(address, channel, function() {
console.log('connected to ' + name + ' '+ address);
//btSerial.write(new Buffer([1]), function(err, bytesWritten) {
//if (err) console.log(err);
});
//btSerial.on('data', function(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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment