iOS - MTU Size for BLE data transfer between iOS device and External Accessory(BluetoothWatch)

14,436

Solution 1

You can use whatever MTU size you want (up to 512).

The value that the connection will use is always the minimum between yours and theirs.

So, if for example they want to use MTU equal to, let's say, 50, then if your MTU is lower than 50, that one will be used; otherwise, whichever value you select above 50 is meaningless, as 50 gets picked.

Solution 2

On an iOS device, the available mtu is 20. It means that you can send 20 bytes of data every time when you set it up as BLE peripheral. If you want to communicate for more than 20 bytes, you have to handle that yourself, referencing the APPLE Central Peripheral sample code

In your case, the problem is not the mtu of iOS device but your external BLE device, because your BLE device is the peripheral device. Since your BLE device is capable of transmitting a large amount of data - 255 bytes, it will be fine to have that mtu.

Solution 3

After connect your device yo your app you should have to write a "characteristic" with:

 [YOURDEVICEINSTANCE writeValue:NSDATAVALUE forCharacteristic:YOURCHARACTESITIC type:CBCharacteristicWriteWithResponse];

We spent a lot of time working with my custom BLE device and my conclusion was:

  • The connection is asymmetric. (you will spent 5ms to transmit from your BLE device to your app and 20ms from your app to your BLE device)
Share:
14,436
RayofHope
Author by

RayofHope

I May Neva Prove To Be Good Enough For E V E R Y O N E But I Am Best For T H E M Who Deserve ME....

Updated on July 26, 2022

Comments

  • RayofHope
    RayofHope almost 2 years

    I'm Working on iOS Application(Objective-C) for Bluetooth watch which using BLE(CoreBluetooth), and my watch is having GATT Bluetooth Profile, iOS application minimum support is from iOS7.

    I wants to know How can we do data transfer between iOS device and external device using Core Bluetooth framework.

    Actually I'm working on the Firmware upgrade section of my Bluetooth watch, My iOS application will get Firmware code (binary data) from web service whenever any update received and then it will send data to Bluetooth watch.

    I have searched and got one Apple Sample code: BTLE_Transfer: https://developer.apple.com/Library/ios/samplecode/BTLE_Transfer/Introduction/Intro.html

    I guess sample code was not useful in my case as its having Central and Peripheral both code and transferring data between two iOS device.

    is there any other way apart from this sample code for BLE data transfer? or it's possible with this sample code only?(if yes how?)

    UPDATED:

    My device have 1 service which have 2 characteristic one for read and one for write.

    According to my workflow using write charateristic:

    1. Using WRITECHARACTERISTIC I'm sending data of firmware code in chunks

    [MYDEVICEINSTANCE writeValue:NSDATACHUNK forCharacteristic:WRITECHARACTERISTIC type:CBCharacteristicWriteWithResponse];

    1. and in delegate method "didWriteValueForCharacteristic" method I'm notifying read characteristic as below

    [MYDEVICEINSTANCE setNotifyValue:TRUE forCharacteristic:READCHARACTERISTIC];

    1. which calls "didUpdateNotificationStateForCharacteristic" delegate method inside that I'm checking if READCHARACTERISTIC isNotifying or not then I call
    [MYDEVICEINSTANCE readValueForCharacteristic:READCHARACTERISTIC];
    
    1. which call delegate method "didUpdateValueForCharacteristic" and I'm reading response using READCHARACTERISTIC.value

    My query:

    I wants to confirm MTU maximum limit allowed by Apple for External device communication from iOS application, which I'm starting in step-1 by sending NSDATACHUNK to BLE Watch from iOS app using writeValue

    I have tested that I can send NSDATACHUNK of MTU=255 size and BLE watch is receiving same successfully.

    I have found in "Apple Sample code: BTLE_Transfer" they are using MTU=20 but, I guess that sample code is for iOS device to iOS device communication (Please, correct me if I'm wrong)

    So, If I use MTU=250 in my iOS application for BLE communication is there any chance that apple will reject my Application?

    Or is there any one that can say what is the maximum limit allowed by Apple for MTU?

    Every suggestion are appreciated,

    Thanks in advance

  • RayofHope
    RayofHope over 9 years
    Hey David, thanks for reply and can you please check my updated question and let me know what is the MTU size you have used in your iOS application?
  • Mr.G
    Mr.G over 7 years
    is there any way that i can read bytes from BLE , coz i my app it reads only 20 bytes , how can exceed this ?? what is the configuration ?? , i checked ios sample for this
  • Niks
    Niks over 5 years
    Hi, can we change the MTU size and give specific like MTU = 244, I am getting data in my iOS application from one BLE device which sending me 244 bytes but I am receiving only 182 bytes. Please suggest. Thanks
  • Bogdan Alexandru
    Bogdan Alexandru over 5 years
    @Niks Even if you are using MTU=244, if the other side only supports 182, then 182 will be used. However even for longer characteristics (e.g. 400 bytes), the OS should support reading the whole data using subsequent requests. If not then you should file a ticket to their SW solution.
  • Pradip Sutariya
    Pradip Sutariya about 3 years
    I am facing the same issue, receiving 182 bytes instead of 234 bytes data in my iOS application. Do you have any solutions to get the full length of data?
  • Lehrian
    Lehrian almost 3 years
    This is not technically correct. BLE has 3 bytes of overhead so if the BLE MTU is 20 then the data that can be sent at one time is MTU-3 or 17 bytes. The default BLE MTU is 23 so the default amount of data that fits in one packet is 20 bytes which I believe is what you are referring to.