Created
October 17, 2014 10:36
-
-
Save SoftwareDreamer/e58a5cea52f81ef6afbe to your computer and use it in GitHub Desktop.
devopenspace2014 connected devices nodejs example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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