1.0.1 • Published 5 years ago

gatttool v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

gatttool logo

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.

Featurenoblegatttool
NodeJS 10 and laterNoYes
gatttool (more stable)NoYes
Central modeYesYes
Peripheral modeNoYes
Raspberry PiYesYes
LinuxYesYes
MacOSYesNo
WindowsYesNo