A Node.js module for implementing BLE (Bluetooth Low Energy) peripherals.
Need a BLE central module? See noble.
Note: macOS / Mac OS X, Linux, FreeBSD and Windows are currently the only supported OSes.
- install the XCode command line tools via
xcode-select --install
- 10.9 or later
- Kernel version 3.6 or above
libbluetooth-dev
bluetoothd
disabled, if BlueZ 5.14 or later is installed. Usesudo hciconfig hci0 up
to power Bluetooth adapter up after stopping or disablingbluetoothd
.System V
:sudo service bluetooth stop
(once)sudo update-rc.d bluetooth remove
(persist on reboot)
systemd
sudo systemctl stop bluetooth
(once)sudo systemctl disable bluetooth
(persist on reboot)
If you're using noble and bleno at the same time, connected BLE devices may not be able to retrieve a list of services from the BLE adaptor. Check out noble's documentation on bleno compatibility
sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev libusb-1.0-0-dev
Make sure node
is on your path, if it's not, some options:
- symlink
nodejs
tonode
:sudo ln -s /usr/bin/nodejs /usr/bin/node
- install Node.js using the NodeSource package
sudo yum install bluez bluez-libs bluez-libs-devel
See Configure Intel Edison for Bluetooth LE (Smart) Development
Make sure you have GNU Make:
sudo pkg install gmake
Disable automatic loading of the default Bluetooth stack by putting no-ubt.conf into /usr/local/etc/devd/no-ubt.conf
and restarting devd (sudo service devd restart
).
Unload ng_ubt
kernel module if already loaded:
sudo kldunload ng_ubt
Make sure you have read and write permissions on the /dev/usb/*
device that corresponds to your Bluetooth adapter.
- node-gyp requirements for Windows
- Python 2.7
- Visual Studio (Express)
- node-bluetooth-hci-socket prerequisites
- Compatible Bluetooth 4.0 USB adapter
- WinUSB driver setup for Bluetooth 4.0 USB adapter, using Zadig tool
npm install bleno@npm:@abandonware/bleno
var bleno = require('bleno');
See examples folder for code examples.
NOTE: bleno.state
must be poweredOn
before advertising is started. bleno.on('stateChange', callback(state));
can be used register for state change events.
var name = 'name';
var serviceUuids = ['fffffffffffffffffffffffffffffff0']
bleno.startAdvertising(name, serviceUuids[, callback(error)]);
Note:: there are limits on the name and service UUID's
- name
- maximum 26 bytes
- service UUID's
- 1 128-bit service UUID
- 1 128-bit service UUID + 2 16-bit service UUID's
- 7 16-bit service UUID
var uuid = 'e2c56db5dffb48d2b060d0f5a71096e0';
var major = 0; // 0x0000 - 0xffff
var minor = 0; // 0x0000 - 0xffff
var measuredPower = -59; // -128 - 127
bleno.startAdvertisingIBeacon(uuid, major, minor, measuredPower[, callback(error)]);
Notes::
- OS X:
- in iBeacon mode your peripheral is non-connectable!
var scanData = Buffer.alloc(...); // maximum 31 bytes
var advertisementData = Buffer.alloc(...); // maximum 31 bytes
bleno.startAdvertisingWithEIRData(advertisementData[, scanData, callback(error)]);
- For EIR format section Bluetooth Core Specification sections and 8 and 18 for more information the data format.
bleno.stopAdvertising([callback]);
Set the primary services available on the peripheral.
var services = [
... // see PrimaryService for data type
];
bleno.setServices(services[, callback(error)]);
bleno.disconnect(); // Linux only