Android 蓝牙 MTU 大小

Android Ble MTU size

我在 android 应用程序中使用 BluetoothGatt.requestMtu(512)。 第一次效果很好 但在 Mtu 自动更改为 23(默认)后立即

不知道是什么问题...

这是一篇日志

`D/BluetoothGatt: setCharacteristicNotification() - uuid: 0000fff1-0000-1000-8000-00805f9b34fb enable: true
D/BluetoothGatt: configureMTU() - device: 74:F0:7D:C0:CB:68 mtu: 512
D/BluetoothGatt: onConfigureMTU() - Device=74:F0:7D:C0:CB:68 mtu=23 status=0
D/BluetoothGatt: discoverServices() - device: 74:F0:7D:C0:CB:68
D/BluetoothGatt: onSearchComplete() = Device=74:F0:7D:C0:CB:68 Status=0
I/gattSuccess: gattSuccess`

这是在 onMtuChanged() 中,所以它可以无限循环

正如 M. Kotzjan 所指出的,这与其他设备支持的 MTU 有关。来自蓝牙规范 v5.2,第 3 卷,G 部分,第 4.3.1 节(交换 MTU):-

This sub-procedure is used by the client to set the ATT_MTU to the maximum possible value that can be supported by both devices when the client supports a value greater than the default ATT_MTU for the Attribute protocol. This sub- procedure shall only be initiated once during a connection.

换句话说,如果您请求 512 的 MTU 并且远程设备回复 23(最小 MTU 值),则连接的 MTU 将为 23。如果您请求 512 并且远程设备回复 100,则连接的 MTU 将为 100。如果您请求 200 并且远程设备回复 512,则连接的 MTU 将为 200。

查看以下link了解更多信息:-