Bluetooth HCI socket binding for Node.js
NOTE: Currently only supports Linux.
npm install bluetooth-hci-socket
var BluetoothHciSocket = require('bluetooth-hci-socket');
var bluetoothHciSocket = new BluetoothHciSocket();
var filter = new Buffer(14);
// ...
bluetoothHciSocket.setFilter(filter);
bluetoothHciSocket.bindRaw([deviceId]); // optional deviceId (integer)
bluetoothHciSocket.bindControl();
Get the device (Bluetooth/BT) address. Note: must be called after bindRaw
.
var btAddress = bluetoothHciSocket.getAddress();
Get the device (Bluetooth/BT) address type. Note: must be called after bindRaw
.
var btAddressType = bluetoothHciSocket.getAddressType(); // returns: 'public' or 'random'
Query the device state. Note: must be called after bindRaw
.
var isDevUp = bluetoothHciSocket.isDevUp(); // returns: true or false
Start or stop event handling:
bluetoothHciSocket.start();
// ...
bluetoothHciSocket.stop();
var data = new Buffer(/* ... */);
// ...
bluetoothHciSocket.write(data);
bluetoothHciSocket.on('data', function(data) {
// data is a Buffer
// ...
});
bluetoothHciSocket.on('error', function(error) {
// error is a Error
// ...
});
See examples folder for code examples.