my.notifyBLECharacteristicValueChange
Use this API enable notification on change of Bluetooth Low Energy (BLE) device characteristics.
Instructions:
- The device characteristics must support
notifyorindicateto use this API. See properties in my.getBLEDeviceCharacteristics for details.
- You must enable this API first before you can use my.onBLECharacteristicValueChange.
- After a successful subscription, the device must actively update the value of the characteristic to trigger my.onBLECharacteristicValueChange.
- Subscription is more efficient and is recommended over the read method.
Note:
Currently simulation in IDE is not supported. Please debug in production environment.
Sample Code
copy
my.notifyBLECharacteristicValueChange({
deviceId: deviceId,
serviceId: serviceId,
characteristicId: characteristicId,
success: (res) => {
console.log(res)
},
fail:(res) => {
},
complete: (res)=>{
}
});Parameters
| Property | Type | Required | Description |
| deviceId | String | Yes | The Bluetooth device ID. |
| serviceId | String | Yes | The UUID of the service corresponding to a Bluetooth characteristic. |
| characteristicId | String | Yes | The Bluetooth characteristic UUID. |
| descriptorId | String | No | Descriptor UUID of the notification. This is Android-specific, the default value is 00002902-0000-10008000-00805F9b34fb. |
| state | Boolean | No | Whether notify or indicate is enabled. |
| success | Function | No | The callback function for a successful API call. |
| fail | Function | No | The callback function for a failed API call. |
| complete | Function | No | The callback function used when the API call is completed. This function is always executed no matter the call succeeds or fails. |