dlt.notifyBLECharacteristicValueChange
Introduction
Notify when the characteristic value changes.
Parameters
Object object
| Property | Type | Default | Required | Description |
|---|---|---|---|---|
| serviceUUID | string | No | UUID of the service of the device | |
| characteristicUUID | string | No | UUID of the characteristic within the service | |
| enable | boolean | No | Whether to enable notifications | |
| success | function | No | Callback function called when the interface is successfully invoked. | |
| fail | function | No | Callback function called when the interface invocation fails. | |
| complete | function | No | Callback function called when the interface invocation is complete (called whether the invocation is successful or not). |
object.success Callback Function
Parameters
Object res
| Property | Type | Description |
|---|---|---|
| success | string | true - Success |
object.fail Callback Function
Parameters
Object res
| Property | Type | Description |
|---|---|---|
| success | string | false - Failure |
| errCode | string | Error code |
Error Code Definitions
| Error Code | Description |
|---|---|
| -1 | Failure |
| 0 | Normal |
| 10000 | Bluetooth adapter not initialized |
| 10001 | Bluetooth not available |
| 10002 | Device not found |
| 10003 | Connection failed |
| 10004 | Already connected |
| 10005 | Characteristic not found |
| 10006 | Descriptor not found |
| 10007 | Location access required for scanning |
| 10008 | System reports an exception |
| 10013 | Invalid data |
| 10014 | Permission not granted |
| 10015 | Adapter 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.