Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 503
hungly Avatar asked Jul 26 '26 08:07

hungly


1 Answers

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

  • Maximising BLE Throughput Using Larger MTU
  • The Ultimate Guide to Android BLE
like image 70
Youssif Saeed Avatar answered Jul 28 '26 22:07

Youssif Saeed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!