my.readBLECharacteristicValue
Use this API to read the data of Bluetooth Low Energy (BLE) device characteristics. The returned information must be obtained by using the callback in the my.onBLECharacteristicValueChange.
Supported types of mini programs: DSL
Instructions:
- The device characteristics must support read to use this API. See properties in my.getBLEDeviceCharacteristics for details.
- Multiple parallel reading and writing calls might cause failures.
- If the reading times out, the error code is 10015. However, my.onBLECharacteristicValueChange interface might return data later. Please consider how to handle this situation.
Note:
Currently simulation in IDE is not supported. Please debug in production environment.
Sample Code
copy
my.readBLECharacteristicValue({
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. |
| 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. |
Success Callback Function
| Property | Type | Description |
| characteristic | Object | Information of the device characteristic. |
characteristic
Information of the Bluetooth device characteristic
| Property | Type | Description |
| characteristicId | String | The Bluetooth characteristic UUID. |
| serviceId | String | The UUID of the service corresponding to a Bluetooth characteristic. |
| value | Hex String | The Bluetooth characteristic value. |