1.0.2 • Published 2 years ago

@particle/device-control-ble-setup-library v1.0.2

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
2 years ago

@particle/device-control-ble-setup-library

Library that provides interfaces to execute the ble setup of a device

Installation

npm install @particle/device-control-ble-setup-library --save

note: you'll need to be signed into an npm account that is a member of the @particle org (docs)

API

StreamWithCallback

A class to write data to a stream. Extends the EventEmitter class.

Kind: global class


new StreamWithCallback(callback)

Constructor

ParamTypeDescription
callbackStreamWithCallback~callbackThe callback used to write data.

streamWithCallback.write(data)

Writes data using a callback.

Kind: instance method of StreamWithCallback

ParamTypeDescription
dataUint8ArrayThe data to write.

BLEDevice

A class that implements the BLEDevice interface.

Kind: global class


new BLEDevice(device, uuids, env)

Constructor.

ParamTypeDescription
deviceDeviceDevice instance which can be retrieved only by calling bleManager.startDeviceScan().
uuidsUUIDs
envObject

bleDevice.name : string

The name of the device.

Kind: instance property of BLEDevice


bleDevice.connect(mobileSecret)

Connects to a device using its mobile secret. It first estalishes a connection, and then tries to find the device characteristic based on the UUIDs provided. It then tries to check the protocol version to finally open a control request channel using the mobile secret.

Kind: instance method of BLEDevice

ParamTypeDescription
mobileSecretstringA string of the mobile secret.

bleDevice.disconnect()

Disconnects from a device closing the control request channel, removing the characteristics and cancelling the device connection.

Kind: instance method of BLEDevice


bleDevice.findCharacteristics(UUIDs)

Finds the characteristics of a mobile's connection service.

Kind: instance method of BLEDevice

ParamType
UUIDsUUIDs

bleDevice.getVersion() ⇒ Promise.<number>

Gets the current protocol version from the read characteristics of the connection.

Kind: instance method of BLEDevice
Returns: Promise.<number> - Promise with a number coming from a decoded base64 input.


bleDevice.checkProtocolVersion()

Checks for the protocol version. If the protocol is different that 2, it throws an error instance of type InvalidProtocolVersionError.

Kind: instance method of BLEDevice


bleDevice.openControlRequestChannel(mobileSecret)

Opens a new control request channel using the mobile's secret.

Kind: instance method of BLEDevice

ParamType
mobileSecretstring

bleDevice.closeControlRequestChannel()

Closes a control requested channel.

Kind: instance method of BLEDevice


bleDevice.scanNetworks() ⇒ Promise.<void>

Scans for nearby networks. Filters invalid names and returns unique SSIDs.

Kind: instance method of BLEDevice
Returns: Promise.<void> - Returns a successful promise with the scanned networks.


bleDevice.joinNewNetwork(network, password) ⇒ Promise.<void>

Joins a scanned network.

Kind: instance method of BLEDevice
Returns: Promise.<void> - Returns a successful promise if network was joinable.

ParamTypeDescription
networkINetworkNetwork interface with information like the SSID and channel.
passwordstringPassword to join the network.

bleDevice.onDisconnect(listener)

Listener function triggered when disconnection happens.

Kind: instance method of BLEDevice

ParamTypeDescription
listenercallbackListener callback that gets executed when disconnecting.

DeviceRequests

A class for capturing device requests

Kind: global class


new DeviceRequests(requestChannel)

Constructor

ParamType
requestChannel*

deviceRequests.request(RequestClass, ReplyClass, type, requestData) ⇒ Promise.<ReplyType>

Send a connection request.

Kind: instance method of DeviceRequests
Returns: Promise.<ReplyType> - Promise

ParamType
RequestClassProtobufMessage.<ReplyType>
ReplyClassProtobufMessage.<ReplyType>
typenumber
requestDataRequestType

deviceRequests.scanNetworks() ⇒ Promise.<Array.<INetwork>>

Scans the nearby networks.

Kind: instance method of DeviceRequests
Returns: Promise.<Array.<INetwork>> - Promise containing the network information


deviceRequests.joinNewNetwork(network, password)

Sends a request to join a new network.

Kind: instance method of DeviceRequests

ParamTypeDescription
networkINetworkINetwork interface
passwordstring

atob(input) ⇒ string

Decode base64 string into a string

Kind: global function
Returns: string - Decoded string

ParamTypeDescription
inputstringBase64 encoded input

atoi(input) ⇒ number

Decode base64 string into a number

Kind: global function
Returns: number - Decoded number

ParamTypeDescription
inputstringBase64 encoded input

Device : Object

A Device interface

Kind: global typedef


UUIDs : Object

A UUID interface

Kind: global typedef
Properties

NameTypeDescription
serviceUUIDstringThe UUID of the service.
versionCharacteristicUUIDstringThe version characteristic UUID of the service.
rxCharacteristicUUIDstringThe receiver characteristic UUID of the service.
txCharacteristicUUIDstringThe transmitter UUID of the service.

ProtobufMessage : Object

A ProtobufMessage interface

Kind: global typedef
Properties

NameType
createfunction

NOTE: Unfortunately, docs have a nasty habit of falling out of date. When in doubt, check usage in tests