1

IOS application is communicating with BLE peripheral using Core-Bluetooth framework. The app has registered for glucose characteristic and is receiving data from the peripheral after every one minute.

It is being observed that, when the application is in idle state there is no disconnection from the BLE peripheral whereas if I navigate between the ViewControllers present in the application then there happens to be continuous disconnection with the BLE peripheral.

The connection parameters set are within the given range as mentioned in Apple's Core-Bluetooth programming guide. Any ideas why the connection keeps on getting disconnecting?

I had also used the BTLE Transfer Source Code present in apple developer site. And had replaced the Transfer service UUID with Glucose service UUID. I had tested this on iPhone 6 with iOS version 8.3. I am still facing the same issue of disconnection.

 -    (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {

   if (self.discoveredPeripheral != peripheral) {
       self.discoveredPeripheral = peripheral;

        [self.centralManager connectPeripheral:peripheral options:nil];
    }
}


-(void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {

    [self.centralManager stopScan];
    [self.data setLength:0];

    peripheral.delegate = self;
    [peripheral discoverServices:@[[CBUUID UUIDWithString:TRANSFER_SERVICE_UUID]]];

}
Maor
  • 3,340
  • 3
  • 29
  • 38
sonal
  • 11
  • 1
  • 4

2 Answers2

0

check you don't explicitly use weak properties to manage your peripherals (by default types are strong), check this issue.

However without any piece of code all I can suggest is to grab a BLE packet sniffer and see who, when and therefore why it sends the disconnection command. In this process beware about the channel hopping, you have 1/3 of chances to capture the channel with the sniffer so just retry until you see the data flow on the screen. If not now, it's always welcome to have a device like that if you will regularly work with Bluetooth Low Energy.

Community
  • 1
  • 1
GoRoS
  • 5,183
  • 2
  • 43
  • 66
0
// method called whenever you have successfully connected to the BLE peripheral
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral
{
    self.myPeripheral = peripheral;
    self.myPeripheral.delegate = self;
    NSString *connected = [NSString stringWithFormat:@"Connected: %@", peripheral.state == CBPeripheralStateConnected ? @"YES" : @"NO"];
    NSLog(@"%@", connected);
}

Put this method, Note: It is a good practice to assign your discovered peripheral to a retained CBPeripheral into centralManager: didConnectPeripheral

//this one line code stops disconnecting device automatically.
[[Manager sharedManager].connected_PeripheralDevice discoverServices:nil];
Jayesh Lathiya
  • 788
  • 6
  • 18