4

I have an app which will be acting as a BLE central (scanning for peripherals), running on iOS 8 and above. Also I have a custom accessory acting as a peripheral (advertises a custom service with custom characteristics).

I found out that default MTU and characteristic sizes are 20 bytes, but they seem to be negotiable up to 512 bytes. Larger sizes would be really useful for my app because I intend to be sending about 20KB of data in bursts, about 10 times per hour.

As I understand, both peripheral and central should negotiate MTU (and characteristic?) sizes during connection phase.

Does this happen automatically or do I have to write some special code in my central app?

How do I determine current MTU and supported max characteristic size in my application?

Will the sizes remain constant during single connection session or can they suddenly change, and then how can my app find out when the change occurs?

I've been reading BLE specification documents and Apple developer documents, but still it's not clear how BLE MTU and characteristic size negotiation works in practice and how to deal with it correctly in my code.

I might be able to contact the peripheral accessory manufacturer and ask for some software tweaks on their side, if necessary; thus I can be sure that they will support larger MTU sizes. I'm just not sure what should I do on iOS side.

JustAMartin
  • 13,165
  • 18
  • 99
  • 183
  • 1
    There is nothing exposed to the developer in Core Bluetooth that allows you to modify the MTU size. Any changes must be negotiated from the peripheral – Paulw11 Mar 01 '17 at 22:20
  • @Paulw11 Thanks, that's ensuring. But what about finding out current MTU size? On classic BT IOBluetoothRFCOMMChannel we have getMTU, but is there anything similar - and is something like that needed at all for CoreBluetooth? – JustAMartin Mar 01 '17 at 22:27
  • @JustAMartin check out the Apple Developer Forums for [CoreBluetooth](https://forums.developer.apple.com/community/core-os/bluetooth). There are some Apple engineers that frequent them. – joeybladb Mar 01 '17 at 22:56
  • @JustAMartin have you solved this problem somehow? I'm facing the same problem. – voiger Apr 27 '17 at 14:33
  • @voiger - not yet for iOS, the project is on hold for a few weeks. I have tried it with Android, though, and I noticed that it automatically negotiates maximum MTU (517) immediately after connection and calls onMtuChanged on both peripheral and central site. Unfortunately, there is no onMtuChanged on iOS, so the only hope is on CBCentral's maximumUpdateValueLength (if running peripheral side) and some mysterious CBPeripheral's maximumWriteValueLengthForType (for central side), which does not even have any documentation on Apple API reference site. – JustAMartin Apr 28 '17 at 07:49
  • 1
    @JustAMartin I've watched couple of WWDC videos and it looks like all the process is fully automated by the CoreBluetooth. And `maximumWriteValueLengthForType` is described in the CBPeripheral.h file as `The maximum amount of data, in bytes, that can be sent to a characteristic in a single write type.`. I've started to use it and it works! ^_^ – voiger Apr 28 '17 at 12:19
  • @voiger Thank you for reporting your results, this means that my guess about `maximumWriteValueLengthForType` was right and I'll be able to use it also in my project. – JustAMartin Apr 28 '17 at 14:38

0 Answers0