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

bluetooth-terminal

v1.4.2

Published

ES6 class for serial communication with Bluetooth Low Energy (Smart) devices

Downloads

58

Readme

bluetooth-terminal

npm CI Coverage Status

BluetoothTerminal is a class written in ES6 for serial communication with Bluetooth Low Energy (Smart) devices from the web using Web Bluetooth API.

With this class you can communicate bidirectionally with your own device through the one General Attribute Profile characteristic that only offered by DIY modules.

Please check out the Web-Bluetooth-Terminal repository to see implementation details in a real life example.

Quick Start

Install

You can use the script directly or install it using npm and require in your code.

npm install bluetooth-terminal

Use

// Obtain configured instance.
let terminal = new BluetoothTerminal();

// Override `receive` method to handle incoming data as you want.
terminal.receive = function(data) {
  alert(data);
};

// Request the device for connection and get its name after successful connection.
terminal.connect().then(() => {
  alert(terminal.getDeviceName() + ' is connected!');
});

// Send something to the connected device.
terminal.send('Simon says: Hello, world!');

// Disconnect from the connected device.
terminal.disconnect();

API

BluetoothTerminal

Bluetooth Terminal class.

Kind: global class


new BluetoothTerminal([serviceUuid], [characteristicUuid], [receiveSeparator], [sendSeparator], [onConnected], [onDisconnected])

Create preconfigured Bluetooth Terminal instance.

| Parameter | Type | Default | Description | | -------------------- | ----------------------------- | ----------- | ------------------------------- | | [serviceUuid] | number | string | 0xFFE0 | Service UUID | | [characteristicUuid] | number | string | 0xFFE1 | Characteristic UUID | | [receiveSeparator] | string | '\n' | Receive separator | | [sendSeparator] | string | '\n' | Send separator | | [onConnected] | Function | undefined | undefined | Listener for connected event | | [onDisconnected] | Function | undefined | undefined | Listener for disconnected event |


setServiceUuid(uuid)

Set number or string representing service UUID used.

Kind: instance method of BluetoothTerminal

| Parameter | Type | Description | | --------- | ------------------------ | ------------ | | uuid | number | string | Service UUID |


setCharacteristicUuid(uuid)

Set number or string representing characteristic UUID used.

Kind: instance method of BluetoothTerminal

| Parameter | Type | Description | | --------- | ------------------------ | ------------------- | | uuid | number | string | Characteristic UUID |


setReceiveSeparator(separator)

Set character representing separator for data coming from the connected device, end of line for example.

Kind: instance method of BluetoothTerminal

| Parameter | Type | Description | | --------- | -------- | ------------------------------------------ | | separator | string | Receive separator with length equal to one |


setSendSeparator(separator)

Set string representing separator for data coming to the connected device, end of line for example.

Kind: instance method of BluetoothTerminal

| Parameter | Type | Description | | --------- | -------- | -------------- | | separator | string | Send separator |


setOnConnected(listener)

Set a listener to be called after a device is connected.

Kind: instance method of BluetoothTerminal

| Parameter | Type | Description | | --------- | ----------------------------- | ---------------------------- | | listener | Function | undefined | Listener for connected event |


setOnDisconnected(listener)

Set a listener to be called after a device is disconnected.

Kind: instance method of BluetoothTerminal

| Parameter | Type | Description | | --------- | ----------------------------- | ------------------------------- | | listener | Function | undefined | Listener for disconnected event |


connect()Promise

Launch Bluetooth device chooser and connect to the selected device.

Kind: instance method of BluetoothTerminal

Returns: Promise - Promise which will be fulfilled when notifications will be started or rejected if something went wrong


disconnect()

Disconnect from the connected device.

Kind: instance method of BluetoothTerminal


receive(data)

Data receiving handler which called whenever the new data comes from the connected device, override it to handle incoming data.

Kind: instance method of BluetoothTerminal

| Parameter | Type | Description | | --------- | -------- | ----------- | | data | string | Data |


send(data)Promise

Send data to the connected device.

Kind: instance method of BluetoothTerminal

Returns: Promise - Promise which will be fulfilled when data will be sent or rejected if something went wrong

| Parameter | Type | Description | | --------- | -------- | ----------- | | data | string | Data |


getDeviceName()string

Get the connected device name.

Kind: instance method of BluetoothTerminal

Returns: string - Device name or empty string if not connected