A Node.js BLE (Bluetooth Low Energy) central module.
Want to implement a peripheral? Checkout bleno
Note: macOS / Mac OS X, Linux, FreeBSD and Windows are currently the only supported OSes. Other platforms may be developed later on.
- install Xcode
- Kernel version 3.6 or above
libbluetooth-dev
sudo apt-get install bluetooth bluez libbluetooth-dev libudev-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
Install the required tools and configurations using Microsoft's windows-build-tools from an elevated PowerShell or cmd.exe (run as Administrator).
npm install --global --production windows-build-tools
node-bluetooth-hci-socket prerequisites
- Compatible Bluetooth 4.0 USB adapter
- WinUSB driver setup for Bluetooth 4.0 USB adapter, using Zadig tool
See @don's set up guide on Bluetooth LE with Node.js and Noble on Windows
This limit is imposed upon by the Bluetooth adapter hardware as well as it's firmware.
Platform | |
---|---|
OS X 10.11 (El Capitan) | 6 |
Linux/Windows - Adapter dependent | 5 (CSR based adapter) |
Some BLE adapters cannot connect to a peripheral while they are scanning (examples below). You will get the following messages when trying to connect :
Sena UD-100 (Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)) : Error: Command disallowed
Intel Dual Band Wireless-AC 7260 (Intel Corporation Wireless 7260 (rev 73)) : Error: Connection Rejected due to Limited Resources (0xd)
You need to stop scanning before trying to connect in order to solve this issue.
npm install noble
var noble = require('noble');
noble.startScanning(); // any service UUID, no duplicates
noble.startScanning([], true); // any service UUID, allow duplicates
var serviceUUIDs = ["<service UUID 1>", ...]; // default: [] => all
var allowDuplicates = <false|true>; // default: false
noble.startScanning(serviceUUIDs, allowDuplicates[, callback(error)]); // particular UUID's
NOTE: noble.state
must be poweredOn
before scanning is started. noble.on('stateChange', callback(state));
can be used register for state change events.
noble.stopScanning();
peripheral.connect([callback(error)]);
peripheral.disconnect([callback(error)]);
peripheral.updateRssi([callback(error, rssi)]);
peripheral.discoverServices(); // any service UUID
var serviceUUIDs = ["<service UUID 1>", ...];
peripheral.discoverServices(serviceUUIDs[, callback(error, services)]); // particular UUID's