Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 4.4 BLE indication data more than 20 byte

I have a question about android 4.4 Bluetooth Low Energy.

I have a BLE dongle with UART Rx pin. I can send bytes data from Rx-pin to BLE dongle, and BLE dongle will send the data to bluetooth host device by indication.

So I have a Rx characteristic value it's property is indication. I send about 80 bytes data to Rx characteristic, but i only get 20 bytes by once callback function onCharacteristicChanged.

But I use iPad mini to indicate this characteristic value, it receives 4 packets one of 20 bytes data and it seems right.

How can I do to receive 80 bytes data like iOS in Android callback function ?

like image 796
user3530962 Avatar asked Apr 14 '14 07:04

user3530962


People also ask

What is ble MTU?

The ATT Maximum Transmission Unit (MTU) is the maximum length of an ATT packet. Per the Bluetooth Core Specification, the maximum length of an attribute can be 512 bytes. In reality, it can be slightly larger than this to accommodate the ATT header. On Android, the maximum MTU can be 517 bytes.

What is BLE in Android?

Bluetooth Low Energy (BLE), available in Android 4.3 and later, creates short connections between devices to transfer bursts of data. BLE remains in sleep mode when not connected. This lets BLE provide lower bandwidth and reduced power consumption compared to Classic Bluetooth.

How does ble send data?

The BLE Send block transmits data or instructions from your Android™ mobile device to a nearby device or sensor using the Bluetooth® Low Energy (BLE) protocol.


3 Answers

Try negotiating a bigger GATT MTU. The default is 23 bytes. The (G)ATT protocol takes up 3 bytes for the header per Notification / Indication. So 20 - 3 = 20 bytes left by default.

On iOS 8, the maximum MTU that iOS will allow is 158 bytes. I'm not sure about what Android allows.

like image 91
Martijn Thé Avatar answered Oct 03 '22 05:10

Martijn Thé


I had exactly the same problem - 20 bytes it is a limitation applied to both indications and notifications. It is defined in the Spec, however I am yet to find it.

If your characteristic is not using either indications or notifications then this constraint doesn't apply and all your data will be sent in chunks of MTU-5 see section section 3.4.6.1 of the BT4.0 spec.

like image 34
eklektek Avatar answered Oct 03 '22 05:10

eklektek


The data is sent in chunks of 20 bytes each. So if you want to receive all 80 bytes, then divide the data in 20 byte chunks and send it in a loop. Refer to Android: Sending data >20 bytes by BLE for clarification.

Remember to add Thread.sleep(200) in the loop so that the characteristic is not overwritten.

like image 28
Ankit Aggarwal Avatar answered Oct 03 '22 05:10

Ankit Aggarwal