Reputation: 129
Suppose I want to transfer some data (100 bytes) by ble and MTU is 50 bytes, can I make a 100 bytes package and just send out one time?
In my test,the data was truncated. So does it means we have to subpackage the data by our app manually and send them out one by one and repackage them manually in the other side?
Does android have any API to enable subpackage and repackage automatically?
gatt.requestMtu(100);
@Override
public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
super.onMtuChanged(gatt, mtu, status);
//// here the mtu is 50
}
Upvotes: 1
Views: 1866
Reputation: 865
When developing a BLE application on Android or other high-level operating systems, you can practically ignore the MTU. Best to leave it up to the system to negotiate the configuration.
However that doesnt mean you can just send data of arbitrary length. With BLE, data is transferred from/to bluetooth service characteristics, and these have a maximum length which you cannot exceed, as well as permissions and access-control flags.
To find your maximum packet length, get the size of the characteristic you writing into. The developer of this characteristic should ideally make sure that the characteristics length is equal to or a multiple of the device's MTU.
The only exception to this is if your characteristic is used for notifications (as opposed to read or write). In this case, the maximum length of the characteristic is equal to the device's MTU.
Upvotes: 2