gatttool
v1.0.1
Published
NodeJS wrapper for BlueZ gatttool
Downloads
28
Readme
Gatttool is a NodeJS wrapper for a BlueZ tool gatttool
. You can easily connect, read, write and listen to notifiacations from your Bluetooth Low Energy device.
Installation
npm i gatttool
or
yarn add gatttool
Example usage
Below is one example from the ./examples
folder .
const gatttool = require("gatttool");
const { Writable } = require("stream");
const ble = new Writable({
objectMode: true,
write: (data, encoding, done) => {
console.log(`[stream] ←${data.toString(encoding)}`);
done();
}
});
const handleData = data => console.log(`[onData] ←${data}`);
(async function() {
gatttool.start({ onData: handleData, stream: ble });
const btAddress = await gatttool.scanFor("FooBar2");
console.log(`Found a BT device at: ${btAddress}`);
if (btAddress) {
setTimeout(() => gatttool.write(`connect ${btAddress}`), 500);
setTimeout(() => gatttool.write("char-desc"), 5000);
setTimeout(
() => gatttool.write("char-write-cmd 0x0012 4e4f44454a53"),
10000
);
setTimeout(() => gatttool.write("exit"), 15000);
}
})();
What makes it different?
This wrapper has no depedencies on the buggy D-Bus or HCI socket implementations. Which leaves you with a pure joy of using Bluetooth Low Energy devices on your Linux-based host machines.
gatttool vs noble
The most popular BLE (central mode) library for NodeJS is noble. It's great but it has its limiations. Below is a table that shows differences between bluezjs and noble.
| Feature | noble | gatttool | | ---------------------- | ------- | -------- | | NodeJS 10 and later | No | Yes | | gatttool (more stable) | No | Yes | | Central mode | Yes | Yes | | Peripheral mode | No | Yes | | Raspberry Pi | Yes | Yes | | Linux | Yes | Yes | | MacOS | Yes | No | | Windows | Yes | No |