2

When the firmware calls to disconnect the peripheral, my delegate gets called, (didDisconnectPeripheral), after that, I start a timer and I try to reconnect in 5 seconds (the timer has repeats enabled).

My didFailToConnectPeripheral does not get called, and neither does didConnectToPeripheral. After about 30 seconds, the chip automatically reconnects with the app.

Even though I try to call [_manager cancelPeripheralConnection:_peripheral]; the board fails to disconnect cleanly.

Does anyone have more information on this "limbo" state that the peripheral finds itself in? I have found these pages: iOS 6 - Bluetooth LE disconnect and iOS CoreBluetooth reconnecting device with UUID and it seems this issue is with Core Bluetooth. Does anyone know how to get around this problem?

I am getting the following error:

Error Domain=CBErrorDomain Code=6 "The connection has timed out unexpectedly." UserInfo=0x1e09c050 {NSLocalizedDescription=The connection has timed out unexpectedly.}

The reason I have to disconnect is because the processor on the board is being used up to do other things and hence the radio cannot be kept alive.

Here is the link to the discussion on apple dev forums: https://devforums.apple.com/message/898902

Community
  • 1
  • 1
stackOverFlew
  • 1,479
  • 2
  • 31
  • 58

1 Answers1

3

The cancelPeripheralConnection method is handled as a signal for Core Bluetooth that your app is not going to use that peripheal any more. Once the house keeping on the iOS side is finished, you get the didDisconnecPeripheral callback. However, this does not mean that the peripheral has been physically disconnected. The BLE connection can still be active but your app does not know about it.

For you it can clearly be the issue that iOS cannot start the new connection while it is still connected.

The best way to solve such issues is to initiate the disconnection on the peripheral side. Create a characteristic in the peripheral and use its modification as a signal for the peripheral to disconnect. Or implement it otherwise but make the disconnection be handled by your protocol and not the Core Bluetooth implementation.

allprog
  • 16,540
  • 9
  • 56
  • 97
  • I am calling the method to disconnect inside of a Timer1 interrupt: "GAPRole_TerminateConnection()" on the peripheral and it still fails to disconect cleanly and the app probably thinks that the device is connected. I am also calling the cancelPeripheralConnection frequently when the first callback is called (didDisconnectPeripheral). After that however, I cannot seem to connect. – stackOverFlew Sep 29 '13 at 21:29
  • Additionally I believe that the reason the peripheral does not start advertising again is because it still thinks it's connected to the iOS app. – stackOverFlew Sep 29 '13 at 21:32
  • 1
    Then this is some issue in your peripheral's code too. Without the code it's hard to tell, but if the peripheral disconnects, then the connection should be broken down. We are doing it with our peripheral which works fine. – allprog Sep 29 '13 at 21:35
  • Well the error I am getting is: Error Domain=CBErrorDomain Code=6 "The connection has timed out unexpectedly." UserInfo=0x1e09c050 {NSLocalizedDescription=The connection has timed out unexpectedly.} In your C code (on the firmware), what did you do to terminate the connection? – stackOverFlew Sep 29 '13 at 21:40
  • 1
    Ours is a bit different, our peripheral goes to deep sleep. The error you see is normal for the cases like our, where the peripheral just disappears. – allprog Sep 29 '13 at 21:53