Negotiate BLE MTU on iOS
Asked Answered
C

3

8

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?

Chronicles answered 1/2, 2017 at 10:46 Comment(2)
I don't believe that you can do anything with the mtu on iOS. It is limited to 20 bytesPikestaff
@Pikestaff 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.Sanorasans
C
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.

Chronicles answered 3/2, 2017 at 8:13 Comment(1)
How did you get the central MTU?Coincide
P
18

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)

Prop answered 20/2, 2017 at 3:28 Comment(6)
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...Sanorasans
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?Jochebed
@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.Fact
The following WDC video "What's New in Core Bluetooth" is well worth your 40 minutes 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": developer.apple.com/documentation/corebluetooth/…Ezana
A tiny clarification: 3 bytes overhead = 1 byte for opcode + 2 bytes for handle ID.Lemmueu
This article is very good "The Ultimate Guide to Apple’s Core Bluetooth" punchthrough.com/core-bluetooth-basicsEzana
M
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))")
Margeret answered 4/9, 2019 at 13:25 Comment(0)
C
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.

Chronicles answered 3/2, 2017 at 8:13 Comment(1)
How did you get the central MTU?Coincide

© 2022 - 2024 — McMap. All rights reserved.