I know the default connection interval for CoreBluetooth is 30 ms. I've read couple of articles that claim they can reduce it 30 ms > by changing the min and max of the interval. I didn't see any explanation of how they were changing the parameters of it? I am assuming this is all in the iOS end.
Currently I am working on a project where the iOS device is sending packets to the bluetooth le device. When I was writing without response, there were a lot of packets being dropped so I added a handshake so once the bluetooth device receives a packet the iOS sends the next packet. This is currently taking a long time to upload a file since the connection interval is 30 ms which I am trying to reduce.
Any suggestions would be helpful
td;lr How do I change the connection interval on iOS
Solution So after doing research there is no public API that allows iOS devices to request for a connection interval change request. For Android this is possible.
There is no API on iOS for a app as master (using CBCentralManager) to modify the initial Connection Parameters when connecting to a peripheral.
However, the slave can suggest new connection parameters using a L2CAP Connection Parameter Update Request (see Bluetooth 4.0 specification, Volume 3, Part A, Section 4.20), which iOS will accept if they are reasonable (see Bluetooth Accessory Design Guidelines for Apple Products section 3.6 “Connection Parameters”). Peripherals should do this because different operating systems have different default connection parameters that might not be optimal for a particular peripheral. For example, if you rare implementing your peripheral in iOS or OSX, call -[CBPeripheralManager setDesiredConnectionLatency:forCentral:. Or, if you are using the TI BLE stack to program a CC2540 or the like, call the function L2CAP_ConnParamUpdateReq.
Related
How do I specify a lower BLE connection interval in iOS?
I believe in iOS the default is 30 ms but can be lowered to 15 ms (as mentioned in 2017 WWDC Whats New In Core Bluetooth).
Apple mentioned the connection interval can be lowered but this does not seem to be documented anywhere.
I need this to be done by the centralManager rather than the peripheral.
Current code:
self.centralManager.connect(self.peripheral, options: nil)
I would expect the options parameter could be the right place for this, but it does not seem to be so https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/peripheral_connection_options.
This https://developer.apple.com/documentation/corebluetooth/cbperipheralmanager/1393277-setdesiredconnectionlatency looked promising but was for an acting peripheral rather than a central.
Is it even possible to do this using CoreBluetooth in iOS?
This question is not really about the Swift language, but about the CoreBluetooth framework. What they talked about in WWDC 2017 was that iOS acting as central now accepts a larger range of connection parameters requested by a peripheral. From what I know, there is no API to change the connection parameters from an app acting as BLE central.
I have a question about connSupervisionTimeout.
I'm writing app with CoreBluetooth. I checked connection parameters and connSupervisionTimeout = 720ms. On the apple website I found that this parameter should be in the range: 2 seconds ≤ connSupervisionTimeout ≤ 6 seconds. Is it possible to increase this using CoreBluetooth? If not how to do this?
Thank's for your help!
There is no way to control this as an iOS third party application ... only the connected accessory can initiate a connection parameter request change
Section 10.6 of the doc I think you are reading alludes to this when it says:
The accessory is responsible for the connection parameters used for the Low Energy connection. The accessory should request connection parameters appropriate for its use case by sending an L2CAP Connection Parameter
Do note, when a connection is initially established, the master of the connection dictates the starting parameter set used.
When the iOS kernel initiates a connection, I usually see it use a set with a 30 ms connection interval, 0 slave latency, and 720ms supervision timeout. I believe the documentation really only applies to future connection parameter change requests initiated by the accessory verse the initial set chosen by iOS
I use an iPhone as a peripheral to communicate with a micro controller (BLE chip in question is the BGM113). After connecting from the MCU, the MCU sends a couple of read and write requests for characteristics serially. Each request takes only a few ms in the MCU. On the iPhone side, responding to each request also only takes a few ms in the relevant methods (peripheralManager:didReceiveWriteRequests: and peripheralManager:didReceiveReadRequest:).
Still, I have roughly 500ms delay between each request. I have a support request running with the bluetooth chip manufacturer to clarify, but my gut feeling tells me that the fruity company is to blame...
Can anyone confirm such delays when reading or writing characteristics?
(more details: all characteristics are in the same service, read and write may happen on the same characteristic serially, there are several characteristics that I operate on.)
Your delay will be between 1 and 2 times the connection interval, so you set the connection interval to match your maximum delay requirement. Note that the energy consumption for the radio is linear to the inverse of the connection interval though.
I am working on a BLE project and the peripheral is a BLE device and central is an iPhone (iOS-10.3.1). I read quite a few posts, they all mentioned that the minimum connection interval for iPhone is 30ms. However, I just wonder, is that possible to get the "connection interval" in the app programmatically? My development environment is XCode8.3.2 + Swift3.1. The BLE device uses nRF51 chip. I will be really grateful if you could post some code or direct me to the right method that I should look into. Thanks
There is no way to get or set the connection interval through Core Bluetooth framework. But you can check the connection interval from Peripheral side using sniffer tool.
Also you can send the connection parameter update from Pheriperal to iOS.
Refer this link for more info (Page no 22)
https://developer.apple.com/hardwaredrivers/BluetoothDesignGuidelines.pdf
On the Android phone, enable Bluetooth HCI snoop logging in Developer settings.
A log file will be created in the internal sdcard folder. Open it in wireshark. It will show you all low level signaling data sent and received over Bluetooth, including BLE connection parameters such as connection interval.
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:
Using WRITECHARACTERISTIC I'm sending data of firmware code in chunks
[MYDEVICEINSTANCE writeValue:NSDATACHUNK
forCharacteristic:WRITECHARACTERISTIC
type:CBCharacteristicWriteWithResponse];
and in delegate method "didWriteValueForCharacteristic" method I'm notifying read characteristic as below
[MYDEVICEINSTANCE setNotifyValue:TRUE
forCharacteristic:READCHARACTERISTIC];
which calls "didUpdateNotificationStateForCharacteristic" delegate method inside that I'm checking if READCHARACTERISTIC isNotifying or not then I call
[MYDEVICEINSTANCE readValueForCharacteristic:READCHARACTERISTIC];
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
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.
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)
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.
The maximum MTU is negotiated between the participating devices on a low level. CoreBluetooth makes this value available via CBPeripheral's maximumWriteValueLength(for: …).
That said, unless you exactly know the behavior of your BLE peripheral, I'm afraid you can't rely on this value. There are devices out there which claim to support the BLE 5.0 specification with QUEUED WRITES – which would lead to pretty high MTUs, such as 512. They do NOT implement it though, thus packages larger than their native MTU will get silently truncated and as of iOS 14, iOS will not detect this!