I am trying to make a BLE connection from iOS devices with a xGM210P dev board acting as a peripheral .I am able to make successful BLE connection with my iOS source code but there is a huge connection time differences in iPhone 6 and iPhone 11 .
iPhone 6 has BLE 4.0 and iPhone 11 has BLE 5.0 inspite of the fact that iphone 11 has BLE 5.0 which is much faster than BLE 4.0 but its connection time is high as compared to iphone 6 .
For making a BLE connection I am using a connectPeripheral method of CoreBluetooth framework. So the connection timings are as follows:
- iPhone 6 running iOS 12.4 takes a total time of ~168ms for making a successful connection.
- iPhone 11 running iOS 14.4 takes a total time of ~560ms for making a successful connection.
Above timings are measured from the event of initiating a connectPeripheral request till I get a callback in didConnectPeripheral delegate method and these timings are very high in iPhone 11 as compared to iPhone 6 .
Below is the code snippet which I am using.
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.central = [[CBCentralManager alloc]initWithDelegate:self queue:nil];
}
Firstly I have initialised the centralManager than checking for the Bluetooth state, if its poweredOn than started with the scanning.
- (void)centralManagerDidUpdateState:(nonnull CBCentralManager *)central {
switch (central.state) {
case CBManagerStateUnknown:
printf("Unknown");
break;
case CBManagerStatePoweredOn:{
CBUUID *readerPeripheral = [CBUUID UUIDWithString:@"FEE2457F-5AB5-FD8C-F24A-0E3FF4A72566"];
NSArray *arr = [NSArray arrayWithObject:readerPeripheral];
[central scanForPeripheralsWithServices:arr options:nil];
break;
}}
Then I get a discovered devboard peripheral in didDiscoveredPeripheral delegate method below.
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary<NSString *,id> *)advertisementData RSSI:(NSNumber *)RSSI{
if (peripheral.name.length > 0 && [peripheral.name isEqualToString:@"DC0998R21"]) {
NSLog(@"advertisementData = %@",advertisementData);
NSLog(@"%@",advertisementData);
NSString * strkCBAdvDataLocalName = [advertisementData valueForKey:@"kCBAdvDataLocalName"];
NSData *datakCBAdvDataManufacturerData = [advertisementData valueForKey:@"kCBAdvDataManufacturerData"];
[central stopScan];
NSLog(@"Connect CALLED");
self.central = central;
self.scannedPeripheral = peripheral;
self.scannedPeripheral.delegate = self;
self.dateConnectionStarted = [NSDate date];
[self.central connectPeripheral:self.scannedPeripheral options:nil];
}}
Then I get a callback in delegate method didConnectPeripheral below.
-(void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral{
NSDate *dateWiteSucessfull = [NSDate date];
NSTimeInterval diff = [dateWiteSucessfull timeIntervalSinceDate:self.dateConnectionStarted];
NSLog(@"TimeTakeninDIDCONNECT=%f",diff);
//THIS diff is ~560ms in iPhone 11 and ~168ms in iPhone 6
CBUUID *UUIDService = [CBUUID UUIDWithString:serviceUUID];
[self.scannedPeripheral discoverServices:[NSArray arrayWithObject:UUIDService]];
}
So basically I am calculating the total time taken from initiating the connection request using connectPeripheral method till I get a callback in didConnectPeripheral method of successful connection happened.
I am not able to understand reason for huge connection time difference between 2 iPhones . I have also gone through this stackoverflow link but no success - Bluetooth Low Energy Lag / Latency on OS X 10.11 El Capitan
I am also reading about the effects of connection parameters like Min and Max Connection interval, slave Latency and tried changing the connection parameters at peripheral's end but still didn't receive any success for reducing the connection timings on iPhone 11.
Any help in this regard would be much appreciated.