user3530962
user3530962

Reputation: 51

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 ?

Upvotes: 5

Views: 4897

Answers (3)

Martijn Thé
Martijn Thé

Reputation: 4704

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.

Upvotes: 7

Ankit Aggarwal
Ankit Aggarwal

Reputation: 2405

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.

Upvotes: 2

eklektek
eklektek

Reputation: 1173

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.

Upvotes: 3

Related Questions