@abandonware/bluetooth-hci-socket

中文文档
0.5.3-12发布于 2024/04/13MITTypeScriptCommonJS近 30 天下载 4万

Bluetooth HCI socket binding for Node.js

原始使用文档
文档目录13 节
  1. Prerequisites
  2. Linux
  3. Windows
  4. Install
  5. Usage
  6. Actions
  7. Events
  8. Examples
  9. Platform Notes
  10. Linux
  11. FreeBSD
  12. OS X
  13. Windows

node-bluetooth-hci-socket

GitHub forks license NPM Fediverse IRC Channel

Bluetooth HCI socket binding for Node.js

NOTE: Currently only supports Linux, FreeBSD and Windows.

Prerequisites

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

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

Install

npm install @abandonware/bluetooth-hci-socket

Usage

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

Actions

Create

var bluetoothHciSocket = new BluetoothHciSocket();

Set Filter

var filter = Buffer.alloc(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 = Buffer.from(/* ... */);

// ...


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

版本与发布记录

@abandonware/bluetooth-hci-socket 共发布 12 个版本,首次发布于 2018/12/19;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.5.3-12latest2024/04/132 年前
0.5.3-112024/02/122 年前
0.5.3-102023/01/043 年前
0.5.3-92022/12/163 年前
0.5.3-82021/10/015 年前
0.5.3-72021/01/265 年前

关于 @abandonware/bluetooth-hci-socket 的常见问题

@abandonware/bluetooth-hci-socket 是什么?

Bluetooth HCI socket binding for Node.js

如何安装 @abandonware/bluetooth-hci-socket?

在项目目录运行 npm install @abandonware/bluetooth-hci-socket,或使用 pnpm add / yarn add / bun add。

@abandonware/bluetooth-hci-socket 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@abandonware/bluetooth-hci-socket 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@abandonware/bluetooth-hci-socket 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=10.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@abandonware/bluetooth-hci-socket 可以商用吗?

@abandonware/bluetooth-hci-socket 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@abandonware/bluetooth-hci-socket 的下载量有多少?

根据 npm 官方下载统计,@abandonware/bluetooth-hci-socket 在 2026/10/05 – 2026/11/03 这 30 天内被下载 40,358 次,日均约 1,345 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@abandonware/bluetooth-hci-socket 还在维护吗?

最新版本 0.5.3-12 发布于 2024/04/13(2 年前);至今共发布 12 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/12/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。