BlePeripheral

This class is a representation of a BLE peripheral in Homey. This class must not be initiated by the developer, but retrieved by calling BleAdvertisement#connect.

Table of Contents

Constructor

new Homey.BlePeripheral()

Properties:
Name Type Description
id string

Id of the peripheral assigned by Homey

uuid string

Uuid of the peripheral

address string

The mac address of the peripheral

addressType string

The address type of the peripheral

connectable boolean

Indicates if Homey can connect to the peripheral

rssi number

The rssi signal strength value for the peripheral

state string

The state of the peripheral

isConnected boolean

If the peripheral is currently connected to Homey

services Array.<BleService>

Array of services of the peripheral. Note that this array is only filled after the service is discovered by {BleAdvertisement#discoverServices} or {BleAdvertisement#discoverService}

advertisement BlePeripheral#Advertisement

Advertisement data of the peripheral

Methods

assertConnected(callbackopt) → {Promise}

Asserts that the device is connected and if not, connects with the device.

Parameters:
Name Type Attributes Description
callback function <optional>
Name Type Description
err Error
Returns:
Type:
Promise

connect(callbackopt) → {Promise}

Connects to the peripheral if Homey disconnected from it

Parameters:
Name Type Attributes Description
callback function <optional>
Name Type Description
err Error
this BlePeripheral
Returns:
Type:
Promise

disconnect(callbackopt) → {Promise}

Disconnect Homey from the peripheral

Parameters:
Name Type Attributes Description
callback <optional>
Name Type Description
err Error
Returns:
Type:
Promise

discoverAllServicesAndCharacteristics(callbackopt) → {Promise}

Discovers all services and characteristics of the peripheral

Parameters:
Name Type Attributes Description
callback function <optional>
Name Type Description
err Error
services Array.<BleService>
Returns:
Type:
Promise

discoverServices(servicesopt, callbackopt) → {Promise}

Discovers the services of the peripheral

Parameters:
Name Type Attributes Description
services Array.<string> <optional>

list of services to discover, if not given all services will be discovered

callback function <optional>
Name Type Description
err Error
services Array.<BleService>
Returns:
Type:
Promise

getInfoString(ic, callbackopt) → {Promise}

Get all available information of this peripheral as a printable string

Parameters:
Name Type Attributes Description
ic number

Indent count

callback function <optional>
Name Type Description
err Error

Will always be null

infoString string

the info string

Returns:
Type:
Promise

(async) getService(uuid, callbackopt) → {Promise}

Get a service with the given uuid

Parameters:
Name Type Attributes Description
uuid string

The uuid of the service

callback function <optional>
Name Type Description
err Error
service BleService
Returns:
Type:
Promise

read(serviceUuid, characteristicUuid, callbackopt) → {Promise}

Shorthand to read a characteristic for given serviceUuid and characteristicUuid

Parameters:
Name Type Attributes Description
serviceUuid string

The uuid of the service that has given characteristic

characteristicUuid string

The uuid of the characteristic that needs to be read

callback function <optional>
Name Type Description
err Error
result Buffer
Returns:
Type:
Promise

readAll(argumentsArray, callbackopt) → {Promise}

Shorthand to read multiple serviceUuid|characteristicUuid combinations

Parameters:
Name Type Attributes Description
argumentsArray Array.<Array.<string>>

Two dimensional array with [serviceUuid, characteristicUuid] tuples

callback function <optional>
Name Type Description
err Error
results Array.<Buffer>
Returns:
Type:
Promise

removeConnectionWarning()

Removes the warning that open connections should be closed in the console The connection warning should only be disabled if there is need to keep the ble device connected for instance when waiting for events

resetConnectionWarning()

Resets the timer for the connection warning

updateRssi(callbackopt) → {Promise}

Updates the RSSI signal strength value

Parameters:
Name Type Attributes Description
callback function <optional>
Name Type Description
err Error
rssi number
Returns:
Type:
Promise

write(serviceUuid, characteristicUuid, data, callbackopt) → {Promise}

Shorthand to write to a characteristic for given serviceUuid and characteristicUuid

Parameters:
Name Type Attributes Description
serviceUuid string

The uuid of the service that has given characteristic

characteristicUuid string

The uuid of the characteristic that needs to be written to

data Buffer

The data that needs to be written

callback function <optional>
Name Type Description
err Error
result Buffer
Returns:
Type:
Promise

writeAll(argumentsArray, callbackopt) → {Promise}

Shorthand to write to multiple serviceUuid|characteristicUuid combinations

Parameters:
Name Type Attributes Description
argumentsArray Array.<Array.<string>>

Two dimensional array with [serviceUuid, characteristicUuid, data] tuples

callback function <optional>
Name Type Description
err Error
results Array.<Buffer>
Returns:
Type:
Promise

Type Definitions

Properties:
Name Type Description
localName string

The local name of the peripheral

manufacturerData string

Manufacturer specific data for peripheral

serviceData Array.<string>

Array of service data entries

serviceUuids Array.<string>

Array of service uuids

Type:
  • Object