title: Taro.readBLECharacteristicValue(option)
sidebar_label: readBLECharacteristicValue
Reads the hexadecimal data values of the BLE device characteristics. Note: The device characteristics must support read to use this method.
Notes
- Multiple parallel calls may cause read failures.
- The information read by the API must be obtained in the callback registered in the
onBLECharacteristicValueChange
method.
Type
(option: Option) => Promise<BluetoothError>
Parameters
Option
Property | Type | Required | Description |
---|---|---|---|
characteristicId | string |
Yes | The Bluetooth characteristic UUID |
deviceId | string |
Yes | The Bluetooth device ID |
serviceId | string |
Yes | The UUID of the service corresponding to a Bluetooth characteristic |
complete | (res: any) => void |
No | The callback function used when the API call completed (always executed whether the call succeeds or fails) |
fail | (res: any) => void |
No | The callback function for a failed API call |
success | (res: Result) => void |
No | The callback function for a successful API call |
Sample Code
// You must perform a callback here to get the information.
Taro.onBLECharacteristicValueChange(function(characteristic) {
console.log('characteristic value comed:', characteristic)
})
Taro.readBLECharacteristicValue({
// This deviceId must have been used to connect the appropriate device via createBLEConnection.
deviceId,
// This serviceId must be obtained in the getBLEDeviceServices API.
serviceId,
// This characteristicId must be obtained in the getBLEDeviceCharacteristics API.
characteristicId,
success (res) {
console.log('readBLECharacteristicValue:', res.errCode)
}
})
API Support
API | WeChat Mini-Program | H5 | React Native |
---|---|---|---|
Taro.readBLECharacteristicValue | ✔️ |