uni-app uni.writeBLECharacteristicValue发送内容报10007

uni-app uni.writeBLECharacteristicValue发送内容报10007

产品分类

uniapp/App

PC开发环境

  • 操作系统:Windows
  • 操作系统版本号:window 10
  • HBuilderX类型:正式
  • HBuilderX版本号:4.56

手机系统

  • 系统:Android
  • 系统版本号:Android 11
  • 厂商:OPPO
  • 机型:OPP a32

页面类型

  • 类型:vue
  • vue版本:vue2

打包方式

云端

项目创建方式

HBuilderX

示例代码

const type = 0x08;
const frameCtrl = 0x00;
const sequence = 0x00;
const data = [0x01];
const buffer = this.buildPacket(type, frameCtrl, sequence, data);
let _this=this
uni.writeBLECharacteristicValue({
deviceId:_this.deviceId,
serviceId:"0000FFFF-0000-1000-8000-00805F9B34F",
characteristicId:"0000FF01-0000-1000-8000-00805F9B34FB",
writeType:"write",
value: buffer,
success(res) {
console.log('writeBLECharacteristicValue successSTA', res.errMsg)
},
fail(err){
console.log( err)
},
})

操作步骤

连接蓝牙后点击发送,直接就报10007

预期结果

会打印成功的内容 writeBLECharacteristicValue successSTA', res.errMsg

实际结果

实际直接报错

{
"errMsg": "writeBLECharacteristicValue:fail property not support",
"errCode": 10007,
"code": 10007
}

bug描述

uni.writeBLECharacteristicValue 第一次发送数据报1007,查过特征值是支持写入的

Image 1 Image 2


更多关于uni-app uni.writeBLECharacteristicValue发送内容报10007的实战教程也可以访问 https://www.itying.com/category-93-b0.html

5 回复

我遇到一样的问题,我有一千多个包要发送,发个几十包就会报这个错,我的解决方法是在fail中暂停一下重试发送这个包。

更多关于uni-app uni.writeBLECharacteristicValue发送内容报10007的实战教程也可以访问 https://www.itying.com/category-93-b0.html


我在fail中暂停一秒发射也还是有这个报错,而且我设置mtu为512,也是这样,数据内容都很短的

回复 1***@sina.cn: 大概要暂停10秒左右才会恢复

你要设置mtu,数据过长也会报错。

错误码10007表示当前特征值不支持写入操作。从你提供的截图来看,特征值属性为Notify,这代表该特征值仅支持订阅通知,不支持写入操作。

在BLE协议中,特征值的属性决定了其可操作类型:

  • Write:支持写入
  • Notify/Indicate:支持订阅通知
  • Read:支持读取

你的代码中使用的特征值0000FF01-0000-1000-8000-00805F9B34FB属性为Notify,因此调用writeBLECharacteristicValue会返回10007错误。

解决方案:

  1. 检查蓝牙设备文档,确认正确的可写入特征值UUID
  2. uni.getBLEDeviceCharacteristics回调中,遍历特征值列表,找到属性包含write的特征值
  3. 使用支持写入的特征值UUID进行数据发送

示例代码:

uni.getBLEDeviceCharacteristics({
  deviceId: deviceId,
  serviceId: serviceId,
  success: (res) => {
    res.characteristics.forEach(characteristic => {
      if (characteristic.properties.write) {
        // 使用这个特征值进行写入
      }
    })
  }
})
回到顶部