dlt.onBLEConnectionStateChange(function listener)
Introduction
Listen for changes in the Bluetooth device's connection state.
Usage Limitations
You must register this listener before calling dlt.createBLEConnection.
Parameters
function listener
The listener function for the Bluetooth device's connection state change event.
Parameters
Object res
Property | Type | Description |
---|---|---|
address | string | The MAC address of the Bluetooth device |
status | number | Current status code |
newState | number | Bluetooth device connection state |
Status Codes
Status | Description |
---|---|
0 | A GATT operation completed successfully |
2 | GATT read operation is not permitted |
3 | GATT write operation is not permitted |
5 | Insufficient authentication for a given operation |
6 | The given request is not supported |
7 | A read or write operation was requested with an invalid offset |
13 | A write operation exceeds the maximum length of the attribute |
15 | Insufficient encryption for a given operation |
143 | A remote device connection is congested |
257 | A GATT operation failed, errors other than the above |
Connection States
newState | Description |
---|---|
0 | The profile is in a disconnected state |
1 | The profile is in a connecting state |
2 | The profile is in a connected state |
3 | The profile is in a disconnecting state |
Sample Code
dlt.onBLEConnectionStateChange(function (res) {
console.log(res);
});
In the sample code provided, dlt.onBLEConnectionStateChange
is used to add a listener for changes in the Bluetooth device's connection state. When the connection state changes, the provided listener function is called, and it logs the information about the connection status to the console.