在Android 4.3-4.4(API 18-20)上请求具有蓝牙低功耗连接的MTU [英] Requesting MTU with Bluetooth Low Energy connection on Android 4.3-4.4 (API 18-20)

查看:116
本文介绍了在Android 4.3-4.4(API 18-20)上请求具有蓝牙低功耗连接的MTU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个蓝牙低功耗应用程序,该应用程序要求MTU大小超过默认的23个字节.

I have a Bluetooth Low Energy Application which requires an MTU size above the default 23 bytes.

尽管Android引入了 BluetoothGatt#requestMTU()在API 21中,是否有任何方法(包括使用私有API)来完成此API 21之前的版本?

Though Android introduced BluetoothGatt#requestMTU() in API 21, is there any way, including use of private APIs, to accomplish this pre API 21?

推荐答案

如果可以控制外围设备,则可以从外围设备发出MTU请求(ATT_OP_MTU_REQ,操作码0x02).如果外围设备要求,Android可以支持更大的GATT MTU(更新:最大值为517个字节),并且会很乐意发送相应的ATT_OP_MTU_RESP.

If you have control over the peripheral device, you can issue an MTU request (ATT_OP_MTU_REQ, opcode 0x02) from the peripheral. Android is capable of larger GATT MTUs (update: 517 bytes is the maximum value), if requested by the peripheral, and will happily send an according ATT_OP_MTU_RESP.

唯一棘手的事情是MTU交换可能不会与零散的读/写重叠.一种解决方法是在给定的握手时间客户端睡眠,在该时间外围设备发送MTU请求.另一个可能的解决方法是对魔术"特性进行读取或写入,以触发MTU交换.

The only tricky thing is that the MTU exchange may not overlap with a fragmented read/write. One workaround might be a client-side sleep at a given time of the handshake, where the peripheral sends an MTU request. Another possible workaround would be a READ or WRITE on a "magic" characteristic that triggers the MTU exchange.

但是,随着MTU的增加,我更经常收到Status = 133错误,这可能是由于较大数据包的较高数据包错误率引起的?

However, with an increased MTU, I'm much more often receiving Status=133 errors, possibly caused by a higher packet error rate with larger packets?

这篇关于在Android 4.3-4.4(API 18-20)上请求具有蓝牙低功耗连接的MTU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆