7

I'm currently developing a BLE App for iOS. In my application I need to implement a segmentation protocol to send large quantities of data using BLE. My application need to have the Central role.

My issue is that I can't get the negotiate MTU. I can get the maximumWriteValueLength of my peripheral but it is bigger that mine and can't find the maximumWriteValueLength of my central object.

Does someone know a way to find the negotiated MTU or a way to access the CBCentral object of my CBCentralManager?

dandan78
  • 13,328
  • 13
  • 64
  • 78
anté75
  • 167
  • 1
  • 1
  • 8
  • I don't believe that you can do anything with the mtu on iOS. It is limited to 20 bytes – Paulw11 Feb 01 '17 at 10:51
  • 1
    @Paulw11 I think you are right about I can't do anything with MTU on iOS but I hope someone have an idea on this subject. About the 20 bytes that you tell me I m limited, I m not agree with you I have already work with iOS BLE and paquet of 150 bytes. I thing the limitation can not be more than 155 bytes. But for this application that will work on iOS and Android I would find a way to not limit my MTU because iOS and Android don't have the same limitation. – anté75 Feb 01 '17 at 12:37

3 Answers3

16

iOS kicks off an MTU exchange automatically upon connection.

Devices running iOS < 10 will request an MTU size of 158. Newer devices running iOS 10 will request an MTU size of 185.

Assuming the device you are connected to supports these sizes, that is what you should see.

You should be able to determine the max payload size negotiated by looking at the maximumUpdateValueLength property of the CBCentral. (Note this will be 3 bytes less than the ATT MTU since that's the overhead for a ATT notification/indication)

chrisc11
  • 814
  • 7
  • 7
  • I totally agree with you, when iPhone is in peripheral mode you can get the negotiate MTU by adding 3 to 'maximumUpdateValueLength' property of the 'CBCentral'. But my question was when the iPhone is in Central mode... – anté75 Feb 21 '17 at 09:12
  • When my ipod is connected as a peripheral to my iPad (both iOS10) I get 74 for the `maximumUpdateValueLength`. Are these values actually device as well as OS version dependent? – Hari Honor Mar 23 '17 at 10:52
  • @Hari Karam Singh - yes, usually the central side asks for its default value and the peripheral side can agree or disagree, depending on its specific BLE implementation. Therefore you can never be 100% sure and it is not good idea to use hard coded MTU values, unless you intend to communicate with only one specific kind of peripheral/central with 100% known fixed MTU size. – JustAMartin May 16 '17 at 12:14
  • 1
    The following WDC video "What's New in Core Bluetooth" is well worth your 40 minutes https://developer.apple.com/videos/play/wwdc2017/712/ Video claims close to 400 Kbps are possible for firmware updates. See example: "Transferring Data Between Bluetooth Low Energy Devices": https://developer.apple.com/documentation/corebluetooth/transferring_data_between_bluetooth_low_energy_devices – Ed of the Mountain Sep 03 '20 at 22:02
  • A tiny clarification: 3 bytes overhead = 1 byte for opcode + 2 bytes for handle ID. – gresolio Dec 10 '20 at 14:04
  • This article is very good "The Ultimate Guide to Apple’s Core Bluetooth" https://punchthrough.com/core-bluetooth-basics/ – Ed of the Mountain Mar 02 '21 at 23:07
1

I don't know if you are looking for this. but in my case I ask to the peripheral sending this message:

print("Max write value: \(peripheral.maximumWriteValueLength(for: .withResponse))")
Dharman
  • 30,962
  • 25
  • 85
  • 135
Juan Gil
  • 21
  • 1
  • 4
0

I will answer for people with same issue.

Right now (February 2017) the MTU of iPhone in Peripheral role is always 158. So what I have found in short solution (just to make some test) is to compare the Central MTU to 158 and take the smaller one. For a solution more stable peripheral will write the MTU size inside a specific characteristic that I will read after the connection.

anté75
  • 167
  • 1
  • 1
  • 8