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

bluetooth-terminal

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bluetooth-terminal

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

  • 1.3.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

bluetooth-terminal

Build Status Coverage Status devDependencies Status Greenkeeper badge

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])

Create preconfigured Bluetooth Terminal instance.

ParameterTypeDefaultDescription
[serviceUuid]number | string0xFFE0Service UUID
[characteristicUuid]number | string0xFFE1Characteristic UUID
[receiveSeparator]string'\n'Receive separator
[sendSeparator]string'\n'Send separator

setServiceUuid(uuid)

Set number or string representing service UUID used.

Kind: instance method of BluetoothTerminal

ParameterTypeDescription
uuidnumber | stringService UUID

setCharacteristicUuid(uuid)

Set number or string representing characteristic UUID used.

Kind: instance method of BluetoothTerminal

ParameterTypeDescription
uuidnumber | stringCharacteristic UUID

setReceiveSeparator(separator)

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

Kind: instance method of BluetoothTerminal

ParameterTypeDescription
separatorstringReceive 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

ParameterTypeDescription
separatorstringSend separator

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

ParameterTypeDescription
datastringData

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

ParameterTypeDescription
datastringData

getDeviceName()string

Get the connected device name.

Kind: instance method of BluetoothTerminal

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

Contribution

Please use the dev branch and feel free to contribute!

Keywords

FAQs

Package last updated on 10 Jul 2018

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