JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1069
  • Score
    100M100P100Q165607F
  • License MIT

Bluetooth HCI socket binding for Node.js

Package Exports

  • bluetooth-hci-socket

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (bluetooth-hci-socket) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

node-bluetooth-hci-socket

Bluetooth HCI socket binding for Node.js

NOTE: Currently only supports Linux and Windows.

Prerequisites

Linux

  • Bluetooth 4.0 Adapter

Windows

This library needs raw USB access to a Bluetooth 4.0 USB adapter, as it needs to bypass the Windows Bluetooth stack.

A WinUSB driver is required, use Zadig tool to replace the driver for your adapter.

WARNING: This will make the adapter unavaible in Windows Bluetooth settings!

Compatible Bluetooth 4.0 USB Adapter's

Name USB VID USB PID
BCM920702 Bluetooth 4.0 0x0a5c 0x21e8
CSR8510 A10 0x0a12 0x0001

Install

npm install bluetooth-hci-socket

Usage

var BluetoothHciSocket = require('bluetooth-hci-socket');

Actions

Create

var bluetoothHciSocket = new BluetoothHciSocket();

Set Filter

var filter = new Buffer(14);

// ...

bluetoothHciSocket.setFilter(filter);

Bind

Raw Channel
bluetoothHciSocket.bindRaw([deviceId]); // optional deviceId (integer)
Control Channel
bluetoothHciSocket.bindControl();

Is Device Up

Query the device state.

var isDevUp = bluetoothHciSocket.isDevUp(); // returns: true or false

Note: must be called after bindRaw.

Start/stop

Start or stop event handling:

bluetoothHciSocket.start();

// ...

bluetoothHciSocket.stop();

Note: must be called after bindRaw or bindControl.

Write

var data = new Buffer(/* ... */);

// ...


bluetoothHciSocket.write(data);

Note: must be called after bindRaw or bindControl.

Events

Data

bluetoothHciSocket.on('data', function(data) {
  // data is a Buffer

  // ...
});

Error

bluetoothHciSocket.on('error', function(error) {
  // error is a Error

  // ...
});

Examples

See examples folder for code examples.

Platform Notes

Linux

Force Raw USB mode

Unload btusb kernel module:

sudo rmmod btusb

Set BLUETOOTH_HCI_SOCKET_FORCE_USB environment variable:

sudo BLUETOOTH_HCI_SOCKET_FORCE_USB=1 node <file>.js

Windows

Force adapter USB VID and PID

Set BLUETOOTH_HCI_SOCKET_USB_VID and BLUETOOTH_HCI_SOCKET_USB_PID environment variables.

Example for USB device id: 050d:065a:

set BLUETOOTH_HCI_SOCKET_USB_VID=0x050d
set BLUETOOTH_HCI_SOCKET_USB_PID=0x065a

node <file>.js