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.

Reference

Type

  1. (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

  1. // You must perform a callback here to get the information.
  2. Taro.onBLECharacteristicValueChange(function(characteristic) {
  3. console.log('characteristic value comed:', characteristic)
  4. })
  5. Taro.readBLECharacteristicValue({
  6. // This deviceId must have been used to connect the appropriate device via createBLEConnection.
  7. deviceId,
  8. // This serviceId must be obtained in the getBLEDeviceServices API.
  9. serviceId,
  10. // This characteristicId must be obtained in the getBLEDeviceCharacteristics API.
  11. characteristicId,
  12. success (res) {
  13. console.log('readBLECharacteristicValue:', res.errCode)
  14. }
  15. })

API Support

API WeChat Mini-Program H5 React Native
Taro.readBLECharacteristicValue ✔️