espressif / esp-idf-provisioning-android

Android Provisioning application for ESP-IDF Unified provisioning
Apache License 2.0
201 stars 132 forks source link

Custom endpoint response truncated to the first 600 bytes (BLE transport) #36

Open lucachapelle opened 3 years ago

lucachapelle commented 3 years ago

I have created a custom endpoint to handle our custom provisioning needs over BLE transport. When the esp response is smaller than 600 bytes, every thing is fine. But if the esp response is bigger, the response is truncated to the first 600 bytes.

How protocomm handle the communication when the request/response size is higher than the MTU? Does protocomm or esp-idf-provisioning-android lib have any known limitation regarding the request/response size?

Thanks for your help.

prasad-alatkar commented 3 years ago

Hi @lucachapelle , according to BLE spec maximum length of attribute value can be 512 Bytes (Ref: version 5.0, Vol 3, Part F, Section 3.2.9). This maximum size is for single GATT operation i.e. READ/WRITE etc. You can perform multiple GATT operations to transfer large data. Can you please send debug logs depicting the issue (menuconfig → Component config → Log output → Default log verbosity to Debug) ? Is it possible for you to share reference app implementation so as to understand the issue better ?

lucachapelle commented 3 years ago

Thank you @prasad-alatka for your answer, this indeed seems to be related to the maximum length of 512 bytes for BLE attribute values (which seem to be set to 600 bytes for Android). Also to supplement this bug report, please note that when the esp response is bigger than 600 bytes, in addition to the response being truncated to 600 bytes, the current protocomm session seem to be corrupted because the requests that were following were not well transmitted (they looked like garbage bytes).

I would expect protocomm to workaround this BLE limitation by performing multiple GATT read/write operations so that it can transparently transfer large data wether we use SoftAP/HTTP or BLE transports.

Please find here debug logs depicting the issue: https://pastebin.com/FWjQ119i Also here is a simple patch to esp-idf-provisioning-android that you can use to reproduce the protocomm BLE max length issue: https://pastebin.com/JkgWbwYg And for the esp32 source code, we are using the wifi_prov_mgr example with the following patch applied: https://pastebin.com/fSKa523u

I also noticed this related issue in esp-idf repository : https://github.com/espressif/esp-idf/issues/3633 (the heap corruption has been fixed, but the issue regarding transactions longer than 512 bytes remain).

I hope these informations will help reproduce and debug this issue. Regards.

lucachapelle commented 3 years ago

Hello @prasad-alatkar , any news on this issue. Have you been able to reproduce it ? Regards .

bbinet commented 3 years ago

This thread may also help to understand and fix this issue: https://stackoverflow.com/questions/48741196/android-ble-client-only-returns-600-byte-of-data-in-oncharacteristicread

prasad-alatkar commented 3 years ago

@lucachapelle @bbinet Sorry I could not follow up on this issue because of some other commitments. There is an ongoing discussion about similar issue internally, I will look into the provided logs and update on potential fix in coming week. Thanks.

bbinet commented 3 years ago

@prasad-alatkar finally have you been able to look at this issue? Thanks.