dcloudio / dcloudio/native-docs

uni.setBLEMTU设置蓝牙最大传输单元无效

Open
#98 2 comments 0 reactions 2 assignees Claimed by @tonlion View on GitHub
Dominant language
No language data
Stars
88
Forks
75
PR merge metrics
No merged PRs in 30d

Description

**问题描述**
uni.setBLEMTU设置mtu为128,像蓝牙设备发送32字节的数据包,但蓝牙设备只能收到20字节,mtu不管设置多少发送超过20字节,设备端只能收到20字节,更换手机测试也一样。写了个原生App的demo设置mtu后发送46字节的数据包,蓝牙设备能接收1帧46字节。

**复现步骤**
[复现问题的步骤]

```
uni.setBLEMTU({
deviceId: deviceId,
mtu: 128,
success: (res) => {
console.log(res)
},
fail: (error) => {
console.log(error)
}
})
const uint8Arr = new Uint8Array([1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3,4,5])
const buffer = uint8Arr.buffer
uni.writeBLECharacteristicValue({
// 这里的 deviceId 需要在 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取
deviceId: deviceId,
// 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
serviceId: writeService,
// 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
characteristicId: writeCharacteristic,
// 这里的value是ArrayBuffer类型
value: buffer,
success: res => {
console.log('writeBLECharacteristicValue success', Array.prototype.slice.call(new Uint8Array(buffer)))
},
fail: error => {
console.log(error)
reject(error)
}
})
```

**预期结果**
[使用简洁清晰的语言描述你希望生效的预期结果]

**实际结果**
writeBLECharacteristicValue success, [Object] [1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3,4,5]
![image](https://user-images.githubusercontent.com/20806179/91955334-96f66080-ed35-11ea-941a-810f7cce5acd.png)

**系统信息:**
- 发行平台: uni-app 安卓端
- 操作系统 Android 10.0 Android 9.0
- HBuilderX版本 HBuilderX 2.8.8
- uni-app版本 [如使用Vue-cli创建/运行项目,则提供`npm run info`的运行结果]
- 设备信息 荣耀v20

**补充信息**
[可选]
setBLEMTU返回{"errMsg":"setBLEMTU:ok"}了
原生app正常排除蓝牙设备的限制

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.