SimpleBLE icon indicating copy to clipboard operation
SimpleBLE copied to clipboard

How to change the MTU of an established connection?

Open spikeyamk opened this issue 1 year ago • 1 comments

I'm using an ESP32 and SimpleBLE and can't seem to change the MTU value which is by default set to 23 with NimBLE and I'm sure the client should be able to request the change of the MTU of an established connection somehow, but I can't seem to find where or how?

I'm actually able to write_request() to a peripheral with 23 bytes long but only receive 20 bytes long packets from notify characteristics from the server.

Please help, thanks in advance!

spikeyamk avatar Nov 22 '23 21:11 spikeyamk

MTU size of 23 is the size any BLE device compliant with BT 4.x upward must support, hence it's the default (or rather min) being used upon engaging a connection. Subsequently the peripheral can initiate a connection parameter update request with a higher MTU size. However, the actual max MTU size depends on the specific implementation on either side of the connection. Also note that a larger MTU size is considered an optional feature with BT4.x upward and not all devices will support/confirm a higher value.

As far as I know it's not possible to set/request a specific MTU size with SimpleBLE (yet). It would be down to what the peripheral would request and what the underlying OS BT stack would confirm.

MTU size is the maximum size of an ATT packet but when sending a write/read/notification packet the packet always includes an OP-Code of 1 byte plus the attribute handle of 2 bytes and hence the actual data of a packet is always 3 bytes less than the MTU size.

eriklins avatar Nov 23 '23 07:11 eriklins