收藏
回答

建议增加writeBLECharacteristicValue 蓝牙写类型type参数设置

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug 设备 /蓝牙-低功耗中心设备 /wx.writeBLECharacteristicValue 微信iOS客户端 Version 8.0.11 2.17.0
一、微信小程序代码段
https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.writeBLECharacteristicValue.html// 向蓝牙设备发送一个0x00的16进制数据
let buffer = new ArrayBuffer(1)
let dataView = new DataView(buffer)
dataView.setUint8(0, 0)

wx.writeBLECharacteristicValue({
  // 这里的 deviceId 需要在 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取
  deviceId,
  // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
  serviceId,
  // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
  characteristicId,
  // 这里的value是ArrayBuffer类型
  value: buffer,
  success (res) {
    console.log('writeBLECharacteristicValue success', res.errMsg)
  }
})
二、根据蓝牙BLE核心规范(针对4.0以上所有版本适用),writeBLECharacteristicValue是有三种种写参数设置。
第一种是WriteWithoutResponse(BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G 4.9.1 Write Without Response)
第二种是Signed Write Without Response(BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G 4.9.2 Signed Write Without Response)
第三种是WriteRequest是有WriteRsponse。(BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G 4.9.3 Write Characteristic Value)

三、对应的安卓和IOS手机系统都有相关的API,
1、安卓如下:
/**
 * Write characteristic, requesting acknoledgement by the remote device
 */
public static final int WRITE_TYPE_DEFAULT = 0x02;
/**
 * Wrtite characteristic without requiring a response by the remote device
 */
public static final int WRITE_TYPE_NO_RESPONSE = 0x01;
/**
 * Write characteristic including authentication signature
 */
public static final int WRITE_TYPE_SIGNED = 0x04;
characteristic_ota_update.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
2、IOS如下
[connectPeripheral writeValue:data forCharacteristic:writeCBCharacteristic type:CBCharacteristicWriteWithoutResponse];//第三个参数type是通过此响应不判断是否成功
[connectPeripheral writeValue:data forCharacteristic:writeCBCharacteristic type:CBCharacteristicWriteWithResponse];//第三个参数type是通过此响应会判断是否成功

四,希望微信小程序writeBLECharacteristicValue的API增加相关的Type类型设置,
目前微信小程序type在都是使用系统默认的设置(安卓的默认type为WriteWithoutResponse,IOS的默认type为WriteWithResponse),这就导致安卓的BLE传输数据比IOS的BLE传输数据快很多。
使得用户体验不佳,希望增加相应type设置,让开发者自己选择type类型,以解决相关IOS传输BLE数据慢的问题。



回答关注问题邀请回答
收藏

2 个回答

  • 逸嘉鱼
    逸嘉鱼
    2021-12-01

    能不能给个时间点?谢谢!

    2021-12-01
    有用
    回复
  • Riven.
    Riven.
    2021-09-23

    已在规划,未来版本会添加相关参数

    2021-09-23
    有用
    回复 7
    • BlueStack
      BlueStack
      2021-09-23
      希望早点出来啦。本来原生BLE的APP,IOS传输速度是比安卓的快的,到了微信小程序这里就反过来了。另外write request类型对于安卓ble传输也有稳定作用,不然传输丢包,协议栈是不会上报应用层的
      2021-09-23
      回复
    • 逸嘉鱼
      逸嘉鱼
      2021-12-01
      能不能提供一个时间点?谢谢!
      2021-12-01
      回复
    • Riven.
      Riven.
      2021-12-01回复逸嘉鱼
      预计这个月
      2021-12-01
      回复
    • Alex
      Alex
      2022-01-24回复Riven.
      你好,iOS WriteWithoutResponse API近期会发布吗?预计下一版本发布时间是?
      2022-01-24
      回复
    • 逸嘉鱼
      逸嘉鱼
      2022-02-07回复Riven.
      iOS WriteWithoutResponse API,什么时候发布?
      2022-02-07
      回复
    查看更多(2)
登录 后发表内容