Android 4.4 BLE indication data more than 20 byte

拜拜、爱过 提交于 2019-12-10 14:05:02

问题


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 ?


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/23054594/android-4-4-ble-indication-data-more-than-20-byte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!