npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ycanince/hci-socket

v1.0.0

Published

Linux bindings for using a Bluetooth controller in Node.js over HCI.

Downloads

6

Readme

node-hci-socket

Linux bindings for using a Bluetooth controller in Node.js over HCI.

This module uses the HCI_CHANNEL_USER feature in the Linux kernel, allowing a process to communicate over HCI directly with a Bluetooth controller.

Setup

Installation:

npm install hci-socket

Usage

Include the HciSocket class:

const HciSocket = require('hci-socket');

List devices:

> HciSocket.getDevList();

[
  {
    devId: 0,
    name: 'hci0',
    bdaddr: 'XX:XX:XX:XX:XX:XX',
    flags: 0,
    type: 'PRIMARY',
    bus: 'USB'
  }
]

Get info about a specific devId:

> HciSocket.getDevInfo(0);

{
  devId: 0,
  name: 'hci0',
  bdaddr: 'XX:XX:XX:XX:XX:XX',
  flags: 0,
  type: 'PRIMARY',
  bus: 'USB'
}

An Error with code 'ENODEV' will be thrown if not found.

Create a HciSocket instance:

var socket = new HciSocket(); // To create a socket for the first found hci device
// OR
var socket = new HciSocket(devId);
  • An Error with code 'ENODEV' will be thrown if not found.
  • An Error with code 'EBUSY' will be thrown if the device is already in use. You could try to stop bluetoothd if it is running.
  • An Error with code 'EPERM' will be thrown if the node process does not have permissions to use the socket. Execute sudo setcap cap_net_admin=ep $(eval readlink -f `which node`) first or run node using sudo.

The HciSocket instance has two methods.

Write a packet:

socket.write(Buffer.from([0x01, 0x03, 0x0C, 0x00])); // sends a Reset command

The packet format used is the same as specified in the Bluetooth Core specification, Vol 4: Host Controller Interface, Part A: UART Transport Layer, Chapter 2: Protocol. Note that even if for example a USB Bluetooth controller is used, the Linux kernel will automatically convert it into this format.

An exception will be thrown if the socket has been closed, or if the argument is not a Buffer with length between 4 and 1028.

Close a socket:

socket.close();

The HciSocket instance has two events defined.

A packet arrives:

socket.on('data', function(buffer) { ... });

The socket gets closed, either explicitly after calling close(), or automatically if the device gets unplugged from the system:

socket.on('close', function() { ... });

A HciSocket instance that has not been closed will keep the node process from exiting.