tt.readBLECharacteristicValue
基础库 1.0.0 开始支持本方法,这是一个异步方法。
读取低功耗蓝牙设备的特征值的二进制数据值。注意,必须设备的特征值支持读操作才可以成功调用。
| 前提条件 | 无 |
| 业务背景 | 无 |
| 使用限制 | 无 |
| 注意事项 | 1. 必须先监听tt.onBLECharacteristicValueChange事件,才能获取读取的数据。
2. 读取的二进制数据会通过tt.onBLECharacteristicValueChange事件的回调函数返回。
3. 请确保目标特征值支持read(读取)操作。
4. 抖音 36.1.0 版本修正了 36.0.0 版本的部分错误码双端不一致问题。 |
| 支持沙盒 | 否 |
| 相关教程 | 无 |
语法
tt.readBLECharacteristicValue(options)
参数说明
options 为 object 类型,属性如下:
| 属性名 | 类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
|---|---|---|---|---|---|
| deviceId | string | 是 | 蓝牙设备 ID。 | 3.87.0 | |
| serviceId | string | 是 | 蓝牙特征值所属服务的 UUID。 | 3.87.0 | |
| characteristicId | string | 是 | 蓝牙特征值的 UUID。 | 3.87.0 | |
| success | function | 否 | 接口调用成功的回调函数 | 1.0.0 | |
| fail | function | 否 | 接口调用失败的回调函数 | 1.0.0 | |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | 1.0.0 |
回调成功
object 类型,属性如下:
| 属性名 | 类型 | 说明 | 最低支持版本 |
|---|---|---|---|
| errMsg | string | "readBLECharacteristicValue:ok" | 3.87.0 |
| errorCode | string | 错误码信息 | 3.87.0 |
回调失败
object 类型,属性如下:
| 属性名 | 类型 | 说明 | 最低支持版本 |
|---|---|---|---|
| errMsg | string | "readBLECharacteristicValue:fail" + 详细错误信息 | 3.87.0 |
| errorCode | string | 错误码信息 | 3.87.0 |
错误码
| errorCode | errMsg | errorType | 说明 | 最低支持版本 |
|---|---|---|---|---|
| 188201 | readBLECharacteristicValue:fail not init | D | 未初始化蓝牙适配器 | 3.87.0 |
| 188203 | readBLECharacteristicValue:fail no device found | F | 小程序框架内部错误,有需要请创建工单咨询 | 3.87.0 |
| 188205 | readBLECharacteristicValue:fail no service found | D | 没有找到指定服务 | 3.87.0 |
| 188206 | readBLECharacteristicValue:fail no characteristic | D | 没有找到指定特征 | 3.87.0 |
| 188207 | readBLECharacteristicValue:fail not connection | F | 小程序框架内部错误,有需要请创建工单咨询 | 3.87.0 |
| 188208 | readBLECharacteristicValue:fail property not supported | D | 当前特征不支持此操作 | 3.87.0 |
| 188209 | readBLECharacteristicValue:fail system error | F | 小程序框架内部错误,有需要请创建工单咨询 | 3.87.0 |
| 188202 | readBLECharacteristicValue:fail not available | F | 小程序框架内部错误,有需要请创建工单咨询 | 3.87.0 |
| 188299 | readBLECharacteristicValue:fail invalid_data | U | 连接deviceId为空或者是格式不正确 | 3.87.0 |
代码示例
// 回调获取信息 tt.onBLECharacteristicValueChange(function (characteristic) { console.log('characteristic value comed:', characteristic) }) tt.readBLECharacteristicValue({ // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接 deviceId, // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取 serviceId, // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取 characteristicId, success(res) { console.log('readBLECharacteristicValue:', res.errCode) } })
