Node BLE APIs

May 19, 2024 · View on GitHub

Classes

Adapter

Adapter class interacts with the local bluetooth adapter

Bluetooth

Top level object that represent a bluetooth session

DeviceEventEmitter

Device class interacts with a remote device.

GattCharacteristicEventEmitter

GattCharacteristic class interacts with a GATT characteristic.

GattServer

GattServer class that provides interaction with device GATT profile.

GattService

GattService class interacts with a remote GATT service.

Functions

createBluetooth()NodeBleInit

Init bluetooth session and return

Typedefs

WritingMode
NodeBleSession : Object

Specs

Adapter

Adapter class interacts with the local bluetooth adapter

Kind: global class
See: You can construct an Adapter session via getAdapter method

adapter.getAddress() ⇒ string

The Bluetooth device address.

Kind: instance method of Adapter

adapter.getAddressType() ⇒ string

The Bluetooth device Address Type. (public, random)

Kind: instance method of Adapter

adapter.getName() ⇒ string

The Bluetooth system name

Kind: instance method of Adapter

adapter.getAlias() ⇒ string

The Bluetooth friendly name.

Kind: instance method of Adapter

adapter.isPowered() ⇒ boolean

Current adapter state.

Kind: instance method of Adapter

adapter.isDiscovering() ⇒ boolean

Indicates that a device discovery procedure is active.

Kind: instance method of Adapter

adapter.startDiscovery()

This method starts the device discovery session.

Kind: instance method of Adapter

adapter.stopDiscovery()

This method will cancel any previous StartDiscovery transaction.

Kind: instance method of Adapter

adapter.devices() ⇒ Array.<string>

List of found device names (uuid).

Kind: instance method of Adapter

adapter.getDevice(uuid) ⇒ Device

Init a device instance and returns it.

Kind: instance method of Adapter

ParamTypeDescription
uuidstringDevice Name.

adapter.waitDevice(uuid, [timeout], [discoveryInterval]) ⇒ Device

Wait that a specific device is found, then init a device instance and returns it.

Kind: instance method of Adapter

ParamTypeDefaultDescription
uuidstringDevice Name.
[timeout]number120000Time (ms) to wait before throwing a timeout expection.
[discoveryInterval]number1000Interval (ms) frequency that verifies device availability.

adapter.toString() ⇒ string

Human readable class identifier.

Kind: instance method of Adapter

Bluetooth

Top level object that represent a bluetooth session

Kind: global class
See: You can construct a Bluetooth session via createBluetooth function

bluetooth.adapters() ⇒ Array.<string>

List of available adapter names

Kind: instance method of Bluetooth

bluetooth.defaultAdapter() ⇒ Adapter

Get first available adapter

Kind: instance method of Bluetooth
Throws:

  • Will throw an error if there aren't available adapters.

bluetooth.getAdapter(adapter) ⇒ Adapter

Init an adapter instance and returns it

Kind: instance method of Bluetooth
Throw: Will throw adapter not found if provided name isn't valid.

ParamTypeDescription
adapterstringName of an adapter

bluetooth.activeAdapters() ⇒ Promise.<Array.<Adapter>>

List all available (powered) adapters

Kind: instance method of Bluetooth

Device ⇐ EventEmitter

Device class interacts with a remote device.

Kind: global class
Extends: EventEmitter
See: You can construct a Device object via getDevice method

device.getName() ⇒ string

The Bluetooth remote name.

Kind: instance method of Device

device.getAddress() ⇒ string

The Bluetooth device address of the remote device.

Kind: instance method of Device

device.getAddressType() ⇒ string

The Bluetooth device Address Type (public, random).

Kind: instance method of Device

device.getAlias() ⇒ string

The name alias for the remote device.

Kind: instance method of Device

device.getRSSI() ⇒ number

Received Signal Strength Indicator of the remote device

Kind: instance method of Device

device.getTXPower() ⇒ number

Advertised transmitted power level.

Kind: instance method of Device

device.getManufacturerData() ⇒ Object.<string, any>

Advertised transmitted manufacturer data.

Kind: instance method of Device

device.getAdvertisingData() ⇒ Object.<string, any>

Advertised transmitted data. (experimental: this feature might not be fully supported by bluez)

Kind: instance method of Device

device.getServiceData() ⇒ Object.<string, any>

Advertised transmitted data.

Kind: instance method of Device

device.isPaired() ⇒ boolean

Indicates if the remote device is paired.

Kind: instance method of Device

device.isConnected() ⇒ boolean

Indicates if the remote device is currently connected.

Kind: instance method of Device

device.pair()

This method will connect to the remote device

Kind: instance method of Device

device.cancelPair()

This method can be used to cancel a pairing operation initiated by the Pair method.

Kind: instance method of Device

device.connect()

Connect to remote device

Kind: instance method of Device

device.disconnect()

Disconnect remote device

Kind: instance method of Device

device.gatt() ⇒ GattServer

Init a GattServer instance and return it

Kind: instance method of Device

device.toString() ⇒ string

Human readable class identifier.

Kind: instance method of Device

"connect"

Connection event

Kind: event emitted by Device
Properties

NameTypeDescription
connectedbooleanIndicates current connection status.

"disconnect"

Disconection event

Kind: event emitted by Device
Properties

NameTypeDescription
connectedbooleanIndicates current connection status.

GattCharacteristic ⇐ EventEmitter

GattCharacteristic class interacts with a GATT characteristic.

Kind: global class
Extends: EventEmitter
See: You can construct a GattCharacteristic object via getCharacteristic method.

gattCharacteristic.getUUID() ⇒ string

128-bit characteristic UUID.

Kind: instance method of GattCharacteristic

gattCharacteristic.getFlags() ⇒ Array.<string>

Defines how the characteristic value can be used.

Kind: instance method of GattCharacteristic

gattCharacteristic.isNotifying() ⇒ boolean

True, if notifications or indications on this characteristic are currently enabled.

Kind: instance method of GattCharacteristic

gattCharacteristic.readValue([offset]) ⇒ Buffer

Read the value of the characteristic

Kind: instance method of GattCharacteristic

ParamTypeDefault
[offset]number0

gattCharacteristic.writeValue(value, [optionsOrOffset])

Write the value of the characteristic.

Kind: instance method of GattCharacteristic

ParamTypeDefaultDescription
valueBufferBuffer containing the characteristic value.
[optionsOrOffset]number | Object0Starting offset or writing options.
[optionsOrOffset.offset]number0Starting offset.
[optionsOrOffset.type]WritingModereliableWriting mode

gattCharacteristic.writeValueWithoutResponse(value, [offset]) ⇒ Promise

Write the value of the characteristic without waiting for the response.

Kind: instance method of GattCharacteristic

ParamTypeDefaultDescription
valueBufferBuffer containing the characteristic value.
[offset]number0Starting offset.

gattCharacteristic.writeValueWithResponse(value, [offset]) ⇒ Promise

Write the value of the characteristic and wait for the response.

Kind: instance method of GattCharacteristic

ParamTypeDefaultDescription
valueBufferBuffer containing the characteristic value.
[offset]number0Starting offset.

gattCharacteristic.startNotifications()

Starts a notification session from this characteristic. It emits valuechanged event when receives a notification.

Kind: instance method of GattCharacteristic

"valuechanged"

Notification event

Kind: event emitted by GattCharacteristic

GattServer

GattServer class that provides interaction with device GATT profile.

Kind: global class
See: You can construct a Device object via gatt method

gattServer.services() ⇒ Array.<string>

List of available services

Kind: instance method of GattServer

gattServer.getPrimaryService(uuid) ⇒ GattService

Init a GattService instance and return it

Kind: instance method of GattServer

ParamType
uuidstring

GattService

GattService class interacts with a remote GATT service.

Kind: global class
See: You can construct a GattService object via getPrimaryService method.

gattService.isPrimary() ⇒ boolean

Indicates whether or not this GATT service is a primary service.

Kind: instance method of GattService

gattService.getUUID() ⇒ string

128-bit service UUID.

Kind: instance method of GattService

gattService.characteristics() ⇒ Array.<string>

List of available characteristic names.

Kind: instance method of GattService

gattService.getCharacteristic(uuid) ⇒ GattCharacteristic

Init a GattCharacteristic instance and return it

Kind: instance method of GattService

ParamTypeDescription
uuidstringCharacteristic UUID.

gattService.toString() ⇒ string

Human readable class identifier.

Kind: instance method of GattService

createBluetooth() ⇒ NodeBleInit

Init bluetooth session and return

Kind: global function
Example

const { createBluetooth } = require('node-ble')

async function main () {
 const { bluetooth, destroy } = createBluetooth()
 const adapter = await bluetooth.defaultAdapter()
 // do here your staff
 destroy()
}

WritingMode

Kind: global typedef
Properties

NameTypeDescription
commandstringWrite without response
requeststringWrite with response
reliablestringReliable Write

NodeBleSession : Object

Kind: global typedef
Properties

NameTypeDescription
bluetoothBluetoothBluetooth session
destroyfuncClose bluetooth session