'BLE SPP (serial) fragmentation on client side

I'm designing serial over BLE, and there seems to be little information on this topic, so I'm wondering perhaps somebody here can help me. I'm using NimBLE stack (modified SPP example) on ESP32 device with MTU size of 180.

I'll try to describe the current situation as best as I can.

There is a GATT server, that implements SPP by exposing notification service. If I try to write to this server from smartphone app (BLE terminal), GATT callback will be called, where I can access the received data. So far so good. Also, if I send package bigger than MTU, the callback will be called as many times as it takes to receive the whole buffer. This works as expected (it handles fragmentation automatically). The event is called on the GATT level, whereas on the Client side, these events are called on GAP.

Now, I'm writing a client app on another ESP32, that connects to the server. After successful connection and subscription to the service, I send a buffer (lets say 3*MTU size) from server to the client. Here, the only thing that gets called is GAP callback where the "notify RX" event was called. The issue here is, that callback only gets called once with the size of 24 bytes, regardless of the MTU size or buffer length.

So how can I send data from server to client in a way that stack automatically fragments the data and I can read it via callback? Is this even possible or do I have to implement my own algorithm?

Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source