-1

We are creating an app(Android and iOS) to connect to an esp32 via BLE using Flutter Blue Plus. The MTU is set to 500, but the message is 800+ bytes long. When connecting from iOS we get all the data successfully, but when connecting from Android we only see a partial message(500 bytes).

While debugging on the esp, I can see that both iOS and Android are triggering two read events, one with an offset of 0 and the second with an offset of 499. I see the second read after the following warning:

BT_GATT: attribute value too long, to be truncated to 499

So in both cases, it seems to be executing the same on the esp32 side. But on Android, I only get a partial message.

  • Is the issue on Android that should be changed or
  • is there something different I should be doing on the esp32 to handle this?
  • Should I maybe generate a notification on the esp32 that there is a second part of the message available or
  • how do I notify Android to read the complete message?

Edit: I'm working on the firmware side of the system and not on the mobile app, so I don't have a lot of information on how it is implemented on Android.

LappiesJA
  • 3
  • 4

1 Answers1

0

A GATT characteristic value can only be 512 bytes maximum, regardless of the MTU. If the characteristic value is longer than MTU then both Android and iOS use a sequence of multiple operations to read or write the whole value.

If you need to send more data than what fits in a characteristic, you can for example send multiple notifications, each containing a different part of your data that you need to send. You then need a mechanism to reassemble the data at the receiver side.

Emil
  • 16,784
  • 2
  • 41
  • 52
  • Thanks for the answer. Just to confirm, so will I send both notifications on the same characteristic? And what I am unsure of is: if I should notify Android that there is a second part of the data coming. How should the Android device know that it is not all the data requested? And is a "notification" the same as a characteristic "read" event? – LappiesJA Aug 15 '23 at 20:32
  • Notifications are one way communication from a GATT Server to a GATT Client. Read operations consist of one request sent by the client followed by a response sent by the server containing data. You can send multiple consecutive notifications on the same characteristic. You will have to implement the split/reassemble yourself in some way. One very simple way is to prepend a byte in each notification being e.g. 0 if it's the last chunk and 1 if more are coming. – Emil Aug 16 '23 at 07:36
  • Okay, I can "send" the same data over a notification as well as on a read event? What is the best convention to use for BLE? Is this only an issue with Android? Because with the current implementation, iOS is able to read all the data from the characteristic even though it's about 800 bytes long. – LappiesJA Aug 16 '23 at 19:10
  • Maybe iOS ignores the requirement of max 512 bytes. Notifications are very common when a device wants to "push" out data. – Emil Aug 16 '23 at 19:42