Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 897
RayofHope Avatar asked Nov 03 '14 10:11

RayofHope


People also ask

What is the maximum MTU size for BLE?

Per the Bluetooth Core Specification, the maximum length of an attribute can be 512 bytes. In reality, it can be slightly larger than this to accommodate the ATT header. On Android, the maximum MTU can be 517 bytes.

What is MTU in Ble?

ATT Maximum Transmission Unit (MTU) is the maximum length of an ATT packet. The ATT MTU is defined by the L2CAP and can be anywhere between 23 and infinity. The implementation of the Bluetooth stack is the key factor of determining the ATT MTU on both client and peripheral.

What is ble IOS?

Introduction: One of the main features of the Bluetooth 4 specification is Bluetooth Low Energy (BLE). Also called Bluetooth smart, this technology allows peripherals to communicate by consuming much less energy than regular Bluetooth.


2 Answers

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.

like image 120
Bogdan Alexandru Avatar answered Oct 24 '22 08:10

Bogdan Alexandru


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)
like image 1
David Santana Avatar answered Oct 24 '22 07:10

David Santana