Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

bluetooth lowenergy - Android Ble MTU size

I use BluetoothGatt.requestMtu(512) in my android application. First time it works well But Right after Mtu is changed automatically to 23 (default)

I dont know what is the problem...

this a log

`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`

this is in onMtuChanged() so it works infinite loop

question from:https://stackoverflow.com/questions/65883084/android-ble-mtu-size

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As M. Kotzjan indicated, this is related to the MTU supported by the other device. From the Bluetooth Specification v5.2, Vol 3, Part G, Section 4.3.1 (Exchange 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.

In other words, if you request an MTU of 512 and the remote device replies with 23 (the minimum MTU value), the connection's MTU will be 23. If you request 512 and the remote device replies with 100, the connection's MTU will be 100. If you request 200 and the remote device replies with 512, the connection's MTU will be 200.

Have a look at the following link for more information:-


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...