一、微信小程序代码段
https:
let buffer = new ArrayBuffer(1)
let dataView = new DataView(buffer)
dataView.setUint8(0, 0)
wx.writeBLECharacteristicValue({
deviceId,
serviceId,
characteristicId,
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、安卓如下:
public static final int WRITE_TYPE_DEFAULT = 0x02;
public static final int WRITE_TYPE_NO_RESPONSE = 0x01;
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];
[connectPeripheral writeValue:data forCharacteristic:writeCBCharacteristic type:CBCharacteristicWriteWithResponse];
四,希望微信小程序writeBLECharacteristicValue的API增加相关的Type类型设置,
目前微信小程序type在都是使用系统默认的设置(安卓的默认type为WriteWithoutResponse,IOS的默认type为WriteWithResponse),这就导致安卓的BLE传输数据比IOS的BLE传输数据快很多。
使得用户体验不佳,希望增加相应type设置,让开发者自己选择type类型,以解决相关IOS传输BLE数据慢的问题。
能不能给个时间点?谢谢!
已在规划,未来版本会添加相关参数