HomeDocs
Skip to main content

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

PropertyTypeDescription
addressstringThe MAC address of the Bluetooth device
statusnumberCurrent status code
newStatenumberBluetooth device connection state

Status Codes

StatusDescription
0A GATT operation completed successfully
2GATT read operation is not permitted
3GATT write operation is not permitted
5Insufficient authentication for a given operation
6The given request is not supported
7A read or write operation was requested with an invalid offset
13A write operation exceeds the maximum length of the attribute
15Insufficient encryption for a given operation
143A remote device connection is congested
257A GATT operation failed, errors other than the above

Connection States

newStateDescription
0The profile is in a disconnected state
1The profile is in a connecting state
2The profile is in a connected state
3The 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.

Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.