Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@stoprocent/bluetooth-hci-socket

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stoprocent/bluetooth-hci-socket

Bluetooth HCI socket binding for Node.js

  • 1.4.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.5K
decreased by-19.46%
Maintainers
0
Weekly downloads
 
Created
Source

node-bluetooth-hci-socket

GitHub forks license NPM

Bluetooth HCI socket binding for Node.js

NOTE: Currently only supports Linux, FreeBSD, Windows or any operating systems when using HCI over uart.

About This Fork

This fork of node-bluetooth-hci-socket exists to introduce several important improvements and address compatibility issues across different operating systems.

  1. System-independent UART HCI driver: I have introduced a driver that allows UART HCI dongles to be used seamlessly across any operating system, making the library much more flexible and portable.

  2. Rewriting Native Code: The C++ native binding code has been fully rewritten from Nan to N-API, ensuring long-term compatibility with modern versions of Node.js. Along with this, I have also resolved numerous issues that plagued the original code, improving both stability and performance.

If you value these contributions and the ongoing maintenance of this project, please consider supporting my work.

Buy me a coffee

Install

npm install @stoprocent/bluetooth-hci-socket

Usage

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

Prerequisites

NOTE: node-gyp is only required if the npm cannot find binary for your OS version otherwise the binaries are prebuilt.

UART/Serial (Any OS)

The reason to use this configuration is more universal transport that can work across multiple operating systems. Idea is to use Zephyr HCI over UART firmware and to interface with HCI over UART.

How to use this?
  1. You will need for example NRF52 module (e.g. nRF52840 DK or nRF52840 USB) or ESP32-WROOM-32
  2. Follow the instructions in the misc/esp32 for ESP32 or misc/nrf52840 for NRF52840.
  3. Enjoy BLE on any OS.

Linux

  • Bluetooth 4.0 Adapter

Note: the node-usb dependency might fail install, this is ok, because it is an optional optional dependency. Installing libudev-dev via your Linux distribution's package manager will resolve the problem.

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 unavailable in Windows Bluetooth settings! To roll back to the original driver go to: Device Manager -> Open Device -> Update Driver Note:

  • that one should select "Delete the driver software for this device" as per Zadig instructions if the generation of the system restoral point by Zadig fails if one wishes to use restore system restoral point as an option.
Compatible Bluetooth 4.0 USB Adapter's
NameUSB VIDUSB PID
BCM920702 Bluetooth 4.00x0a5c0x21e8
BCM920702 Bluetooth 4.00x0a5c0x21f1
BCM20702A0 Bluetooth 4.00x19ff0x0239
BCM20702A0 Bluetooth 4.00x04890xe07a
BCM20702A0 Bluetooth 4.00x413c0x8143
CSR8510 A100x0a120x0001
Asus BT-4000x0b050x17cb
Intel Wireless Bluetooth 62350x80870x07da
Intel Wireless Bluetooth 72600x80870x07dc
Intel Wireless Bluetooth 72650x80870x0a2a
Intel Wireless Bluetooth 82650x80870x0a2b
Belkin BCM20702A00x050D0x065A
Dell Precision 55300x80870x0025
Compatible Bluetooth 4.1 USB Adapter's
NameUSB VIDUSB PID
BCM2045A0 Bluetooth 4.10x0a5c0x6412
Marvell AVASTAR0x12860x204C

Actions

Create
var bluetoothHciSocket = new BluetoothHciSocket();
Set Filter
var filter = new Buffer(14);

// ...

bluetoothHciSocket.setFilter(filter);

Note: setFilter is not required if bindRaw is used.

Bind
Raw Channel
bluetoothHciSocket.bindRaw([deviceId]); // optional deviceId (integer)
User Channel
bluetoothHciSocket.bindUser([deviceId]); // optional deviceId (integer)

Requires the device to be in the powered down state (sudo hciconfig hciX down).

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

FreeBSD

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

OS X

Disable CSR USB Driver
sudo kextunload -b com.apple.iokit.CSRBluetoothHostControllerUSBTransport
Disable Broadcom USB Driver
sudo kextunload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport

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

Keywords

FAQs

Package last updated on 01 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc