1

Problem statement : if have multiple BLE's at my end and i connect them one by one. but now when more than 1 BLE goes out of range at the same time i am not able to detect the state in central manager of core bluetooth framework.

Explanation -

1) if i have a single BLE and i connect to that BLE, when that BLE goes out of range it calls - (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error method of peripheral.

2) In - (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error method i have given a call for - (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral to get it connected whenever the BLE again comes in the range.

3) This behaviour works fine for when single BLE moves out of range at a time. and connect again when comes in the range.

4) but above behaviour not works well when more than one BLE's goes out of range at the same time.

here is my - (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error code

- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {

    [self.btMainDashboardViewController.tagsTableView reloadData];

      for (CBPeripheral *peripheral in self.btMainDashboardViewController.app.addedTagsArray) {
    if (peripheral.state == CBPeripheralStateDisconnected) {
      // if tag is not released go for autoconnection
      [self.centralManager connectPeripheral:peripheral options:nil];
    }
  }
}

Thanks in advance.

Nik
  • 1,679
  • 1
  • 20
  • 36
  • Are you saying that having multiple pending `connect` operations on your CBCentralManager doesn't work? Can you show your code for `didDisconnectPeripheral` ? – Paulw11 Oct 05 '16 at 12:20

1 Answers1

0

Relying on the BLE connection and respective callbacks is not the right method for checking if a device is out of range. Because the connection can be cancelled by the OS or the other device at any time.

I would suggest to use BLE scanning with duplicates turned on and keep track of the device via the RSSI (signal strength). Depending on your use case you could either determine a device out of range when the RSSI drops below a threshold or when you stopped scanning the device.

Hope this helps!

p2pkit
  • 1,159
  • 8
  • 11