Module: Toybox.BluetoothLowEnergy
Overview
The BluetoothLowEnergy module provides access to Generic BLE communication functionality in the central role. Including the ability to scan for peripheral devices, pair with sensors, and performing GATTC operations on a peripheral
This module also provides several sets of constants:
Classes Under Namespace
Classes: BleDelegate, Characteristic, Descriptor, Device, DevicePairException, InvalidRequestException, Iterator, ProfileRegistrationException, ScanResult, Service, Uuid, UuidFormatException
Constant Summary
-
Status
-
ScanState
-
ConnectionState
-
WriteType
Name | Value | Since | Description | See Also |
---|---|---|---|---|
STATUS_SUCCESS | 0 | API Level 3.1.0 |
Operation Successful |
|
STATUS_NOT_ENOUGH_RESOURCES | 1 | API Level 3.1.0 |
Operation failed due to lack of resources |
|
STATUS_READ_FAIL | 12 | API Level 3.1.0 |
Read Request Failed |
|
STATUS_WRITE_FAIL | 14 | API Level 3.1.0 |
Write Request Failed |
|
STATUS_GATT_INSUFFICIENT_AUTHENTICATION_FAIL | 18 | API Level 4.2.5 |
GATT operation failed due to insufficent authentication |
|
STATUS_GATT_INSUFFICIENT_ENCRYPTION_FAIL | 19 | API Level 4.2.5 |
GATT operation failed due to insufficent encryption |
|
STATUS_ENCRYPTION_BOND_FAIL | 100 | API Level 4.2.5 |
Initial Bond Procedure Failed |
|
STATUS_ENCRYPTION_PEER_KEYS_LOST | 101 | API Level 4.2.5 |
Peer reports that its keys have been lost. |
|
STATUS_ENCRYPTION_SECURITY_INSUFFICIENT | 102 | API Level 4.2.5 |
Peer Attempted to Reduce Key Security Level from a previous bond |
Name | Value | Since | Description | See Also |
---|---|---|---|---|
SCAN_STATE_OFF | 0 | API Level 3.1.0 |
BLE scanning disabled |
|
SCAN_STATE_SCANNING | 1 | API Level 3.1.0 |
BLE scanning active |
Name | Value | Since | Description | See Also |
---|---|---|---|---|
CONNECTION_STATE_DISCONNECTED | 0 | API Level 3.1.0 |
Device is Disconnected |
|
CONNECTION_STATE_CONNECTED | 1 | API Level 3.1.0 |
Device is Connected |
Name | Value | Since | Description | See Also |
---|---|---|---|---|
WRITE_TYPE_WITH_RESPONSE | 0 | API Level 3.1.0 |
Write with response |
|
WRITE_TYPE_DEFAULT | 1 | API Level 3.1.0 |
Write without response (Default write type) |
Instance Method Summary collapse
-
cccdUuid() as BluetoothLowEnergy.Uuid
Retrieves the CCCD Uuid.
-
getAvailableConnectionCount() as Lang.Number
Accessor for determining the number of available connections.
-
getBondedDevices() as BluetoothLowEnergy.Iterator
Retrieve an Iterator of devices that the Application has bonded with that the system has saved bond information for.
-
getPairedDevices() as BluetoothLowEnergy.Iterator
Retrieve an Iterator of all currently paired devices accessible to the Application.
-
longToUuid(mostSigBits as Lang.Long, leastSigBits as Lang.Long) as BluetoothLowEnergy.Uuid
Converts long representation of a UUID to a Uuid object.
-
pairDevice(scanResult as BluetoothLowEnergy.ScanResult) as BluetoothLowEnergy.Device or Null
Pairs a peripheral device seen in scanning with the system.
-
registerProfile(profile as { :uuid as BluetoothLowEnergy.Uuid, :characteristics as Lang.Array<{ :uuid as BluetoothLowEnergy.Uuid, :descriptors as Lang.Array<BluetoothLowEnergy.Uuid> }> }) as Void
Registers a Bluetooth Profile Definition Call this function to define all of the Profiles that will be used in the application.
-
setDelegate(delegate as BluetoothLowEnergy.BleDelegate) as Void
Sets the Delegate Handler for Bluetooth Asynchronous Callbacks An application can only have 1 registered delegate.
-
setScanState(scanState as BluetoothLowEnergy.ScanState) as Void
Starts the BLE Scanning Operations Once scanning is started onScanResults() will be called on the registered BleDelegate as Advertising data is received.
-
stringToUuid(str as Lang.String) as BluetoothLowEnergy.Uuid
Converts the String Representation of a UUID into a Uuid Object.
-
unpairDevice(device as BluetoothLowEnergy.Device) as Void
Unpairs a peripheral device from the system If the device is connected the BLE Subsystem will disconnect from the device and will not attempt to reconnect.
Instance Method Details
cccdUuid() as BluetoothLowEnergy.Uuid
Retrieves the CCCD Uuid
getAvailableConnectionCount() as Lang.Number
Accessor for determining the number of available connections
getBondedDevices() as BluetoothLowEnergy.Iterator
Retrieve an Iterator of devices that the Application has bonded with that the system has saved bond information for.
getPairedDevices() as BluetoothLowEnergy.Iterator
Retrieve an Iterator of all currently paired devices accessible to the Application
longToUuid(mostSigBits as Lang.Long, leastSigBits as Lang.Long) as BluetoothLowEnergy.Uuid
Converts long representation of a UUID to a Uuid object
pairDevice(scanResult as BluetoothLowEnergy.ScanResult) as BluetoothLowEnergy.Device or Null
Pairs a peripheral device seen in scanning with the system.
The BLE Subsystem will begin to search for the device specified by the scanResult parameter. Once the device is found and connected, onConnectedStateChanged() will be called on the registered BleDelegate with the associated Device object
This pairing does not persist across application instances.
registerProfile(profile as { :uuid as BluetoothLowEnergy.Uuid, :characteristics as Lang.Array<{ :uuid as BluetoothLowEnergy.Uuid, :descriptors as Lang.Array<BluetoothLowEnergy.Uuid> }> }) as Void
Registers a Bluetooth Profile Definition
Call this function to define all of the Profiles that will be used in the application. Only registered characteristics and descriptors will be available when performing GATT operations
When the operation is completed, onProfileRegister() will be called on the registered BleDelegate with the UUID and a Status.
Registration can fail if too many profiles are registered, the current limit is 3.
setDelegate(delegate as BluetoothLowEnergy.BleDelegate) as Void
Sets the Delegate Handler for Bluetooth Asynchronous Callbacks
An application can only have 1 registered delegate. Subsequent calls to this function will override the current delegate
setScanState(scanState as BluetoothLowEnergy.ScanState) as Void
Starts the BLE Scanning Operations
Once scanning is started onScanResults() will be called on the registered BleDelegate as Advertising data is received.
stringToUuid(str as Lang.String) as BluetoothLowEnergy.Uuid
Converts the String Representation of a UUID into a Uuid Object
unpairDevice(device as BluetoothLowEnergy.Device) as Void
Unpairs a peripheral device from the system
If the device is connected the BLE Subsystem will disconnect from the device and will not attempt to reconnect. If the device is not connected the system will stop searching for the device.