Easy to use Node.js Bluez5 D-Bus library.
npm install bluez
const Bluez = require('bluez');
// Initialize bluetooth interface
const bluetooth = new Bluez();
await bluetooth.init();
// listen on first bluetooth adapter
const adapter = await bluetooth.getAdapter();
// Register callback for new devices
adapter.on('DeviceAdded', (address, props) => {
console.log("Found new Device " + address + " " + props.Name);
});
await adapter.StartDiscovery();
console.log("Discovering");
Custom Agents and Profiles can be implemented by extending Agent / Profile base classes.
Then use bluez.registerAgent(agent, capability)
and bluez.registerProfile(profile, options)
to activate them.
Have a look at the examples or tests for more detailed usage information.
The API is based mostly on Bluez's DBus interface. Its documentation can be found in its repository.
Additionally this library provides some convenience functions which can be found in API.md.
There is also low level access to the underlying Dbus interfaces available. Please have a look at dbus.md.
- Node.js 12 and 14
- Bluez 5.50 Ubuntu 18.04
- Bluez 5.53 Ubuntu 20.04
- Bluez 5.48 Debian Stretch
- Bluez 5.50 Debian Buster
- Bluez 5.54 Debian Sid
Older Bluez version should work, but might miss some functions. However I can not recommend using GATT with Bluez < 5.48.
- Underling Dbus library was replaced by dbus-next. If you depend on the old library, do not update.
- bluetooth-socket is no longer a required dependency, if your project depends on it install it directly.
Device.getService()
was renamed toDevice.getGattService()
Bluez.getDevice()
was moved toAdapter.getDevice()
Bluez.getAllDevicesProps()
was moved toAdapter.listDevices()
Bluez.on("device")
was moved toAdapter.on("DeviceAdded")
Bluez.registerStaticKeyAgent()
was replaced byBluez.registerAgent(new SimpleAgent(pin))
Bluez.registerSerialProfile()
was removed. See example/serial.js for new usage
- Characteristic Values are now always
Buffers
- Characteristic, Descriptor and Service properties where changed to functions
- RawFdSocket was removed and replaced by bluetooth-socket module
Bluez.registerDummyAgent
was renamed toBluez.registerStaticKeyAgent
which takes a pin code as argumentBluez.getAllDevicesAddresses
was renamed toBluez.getAllDevicesProps
which returns all properties not only the address.