HomeDocs
Skip to main content

dlt.notifyBLECharacteristicValueChange

Introduction

Notify when the characteristic value changes.

Parameters

Object object

PropertyTypeDefaultRequiredDescription
serviceUUIDstringNoUUID of the service of the device
characteristicUUIDstringNoUUID of the characteristic within the service
enablebooleanNoWhether to enable notifications
successfunctionNoCallback function called when the interface is successfully invoked.
failfunctionNoCallback function called when the interface invocation fails.
completefunctionNoCallback function called when the interface invocation is complete (called whether the invocation is successful or not).

object.success Callback Function

Parameters

Object res

PropertyTypeDescription
successstringtrue - Success

object.fail Callback Function

Parameters

Object res

PropertyTypeDescription
successstringfalse - Failure
errCodestringError code

Error Code Definitions

Error CodeDescription
-1Failure
0Normal
10000Bluetooth adapter not initialized
10001Bluetooth not available
10002Device not found
10003Connection failed
10004Already connected
10005Characteristic not found
10006Descriptor not found
10007Location access required for scanning
10008System reports an exception
10013Invalid data
10014Permission not granted
10015Adapter already initialized

Sample Code

dlt.notifyBLECharacteristicValueChange({
serviceUUID: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
characteristicUUID: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
enable: true,
success: function (res) {
console.log('notifyBLECharacteristicValueChange success', res);
},
complete: function (res) {
console.log('notifyBLECharacteristicValueChange complete', res);
},
fail: function (res) {
console.log('notifyBLECharacteristicValueChange fail', res);
},
});

In the provided sample code, the notifyBLECharacteristicValueChange function is called to enable notifications for a specific Bluetooth characteristic. The success callback logs a success message, and the complete callback logs a complete message. If the operation fails, the fail callback logs an error message.

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