Reputation: 448
Introduction
I am involved in developing an Android application that controls a physical device via BLE. One of the features of the app is to send a large amount of data. My goal is to try to optimize this data flow.
State of art
I created a test Activity with some buttons for the main functions.
At class level I declared the objects that will be used:
private BluetoothManager mBluetoothManager;
private BluetoothAdapter mBluetoothAdapter;
private BluetoothLeScanner mBluetoothLeScanner;
private BluetoothGatt mBluetoothGatt = null;
These objects are initialized in the onCreate method
mBluetoothManager = getApplicationContext().getSystemService(BluetoothManager.class);
mBluetoothAdapter = mBluetoothManager.getAdapter();
mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
The operations I perform are quite basic and work correctly.
I have a button to call startScan()
on the mBluetoothLeScanner
object.
I have another button to call stopScan()
.
In the onScanResult
callback, I fill a HashSet of existing devices.
After stopping the scan I use a drop-down menu to show all discovered devices. By tapping on an item, I start the connection with the selected BluetoothDevice.
device.connectGatt(activity, false, gattCallback, BluetoothDevice.TRANSPORT_LE);
Problems
When I connect, if the device sends the app an MTU exchange request then the app responds with 220. If on the device side this request is not executed, the app still sends a request with the value 220. It therefore appears that, one way or another, a negotiation with an MTU size of 220 is exchanged during connection.
After connecting I receive the BluetoothGatt object directly from the callback:
onConnectionStateChange(BluetoothGatt gatt, int status, int newState)
If on this object I call
boolean result = gatt.requestMtu(512);
result is always true.
In any case in the callback
onMtuChanged(BluetoothGatt gatt, int mtu, int status)
the mtu value is always 220
Furthermore, on the device side, I can't find any trace of any new negotiations.
Questions time
Why does the app always return the value of 220? How do I increase the value?
requestMtu(515) doesn't seem to work.
Note: I have used several tablets with Android 6, 8, 10, 12 and 14 but the exchanged value is always 220.
Does anyone have any idea what is happening and how it can be resolved?
Thank you all
Upvotes: 0
Views: 154