1

I have created an iphone app that pairs with an Android watch.

Whenever the connection is lost between the devices I send an auto reconnect.

if let array:NSArray = self.centralManager.retrievePeripheralsWithIdentifiers([(reconnectedPeripheral?.identifier)!]){
        if array.count > 0 {
            let peripherals:CBPeripheral = array[0] as! CBPeripheral
            centralManager.connectPeripheral(peripherals, options: nil);
            self.scannedPeripheral = peripherals
            self.scannedPeripheral?.delegate = self;
            scanType = .Reconnect
        }

    }

I also have a manual reconnect button which lets the user reconnect manually in case auto reconnect doesn't work. Above code is called in case of manual reconnect as well.

What will happen if a connection request is sent to the watch twice? Will the watch receive two connection requests?

Amogh Shettigar
  • 275
  • 2
  • 3
  • 18
  • Possible duplicate of [CoreBluetooth - Can connectPeripheral be called multiple times](https://stackoverflow.com/questions/17935287/corebluetooth-can-connectperipheral-be-called-multiple-times) – Md. Mostafizur Rahman Feb 02 '18 at 10:17
  • @Md.MostafizurRahmanMafi the link in your comment is for multiple connects to multiple devices. I am sending multiple connects to a single device. – Amogh Shettigar Feb 02 '18 at 10:22
  • It depends on the device software. Generally it won't allow another connection (it will consider the first one first). When I was working with Raspberry Pi and Arduino, both after first connection were even impossible to be found while scanning for peripherals. But as I said - much depends on software – M. Wojcik Feb 02 '18 at 10:57
  • @Amogh Shettigar- why you are not trying it from your apps? Implement all delegates of central manager with errors and check. May be it will throw error like "central manager is already trying to connect". Let us know the exact result if you found. – Md. Mostafizur Rahman Feb 02 '18 at 11:01
  • agree best is trying by self. @Amogh Shettigar - you could for example try to implement `didFailToConnect` – M. Wojcik Feb 02 '18 at 11:09
  • @Md.MostafizurRahmanMafi I am sending the reconnects from the apps. Multiple requests could be sent in the case that the device is out of range. In this case there will be no callback and there is no way that I can check whether or not I have already sent a connect request to the device. My app is acting as a central. If we try to send multiple connect requests to the same app then the framework allows it – Amogh Shettigar Feb 03 '18 at 12:15

1 Answers1

0

According to the BLE standard it is illegal for two devices to have more than one connection at the same time. It should be taken care of by the controller that it simply drops the connection request (but who knows if there are faulty controllers who forgets this).

Anyway, the slave must perform connectable advertising in order to accept a new connection.

I'm also pretty sure that iOS will never try to connect to the same device more than once. If you call connectPeripheral multiple times I think that's OK. Also if you have two apps connecting to the same slave it will "multiplex" the two apps to a single GATT connection.

Emil
  • 16,784
  • 2
  • 41
  • 52
  • Sometimes there is a connection drop happening between the Android watch and the iPhone app. The watch developers have debugged their end of the code and have said that it may be happening because two connect requests are being sent simultaneously to the Bluetooth stack. They have no control over the BT stack code. – Amogh Shettigar Feb 03 '18 at 12:21
  • That would sound very strange. You could use an air sniffer that captures the packets so you see what happens. – Emil Feb 03 '18 at 14:58
  • @AmoghShettigar if it's true what you say than it's as I wrote in the comment under your question: it depends on the device's (the one you are trying to connect) software – M. Wojcik Feb 03 '18 at 18:34