iOS Question BLE disconnect event

Discussion in 'iOS Questions' started by megaB4x, Jun 30, 2015.

  1. megaB4x

    megaB4x Member Licensed User

    Hi,

    After few minutes BLE connection gets disconnected. I assume it is normal when iOS decides to do so in order to clear memory.

    The problem is, I can't re-initiate the connection after it's disconnected. I am using scan command but does not work. What else needs to be done in order to re-scan and connect again?

    Code:
    Sub Manager_Disconnected
        lblStatus.Text = 
    LastException
        manager.Scan(
    Null)
    End Sub
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Maybe the peripheral device is turned off? iOS will not disconnect the BLE if your app is in the foreground.
     
  3. megaB4x

    megaB4x Member Licensed User

    It's not the peripheral because I tried on LightBlue and BLE Explorer apps it doesn't disconnect.
    Let's take another example: peripheral goes out of range and connection get disconnected and then it comes back in range. If I click on the "Scan and Connect" button it starts scanning and connects fine but if I add manager.scan(Null) command as shown above inside Disconnected event it does not initiate scanning. I am missing something here that needs to be done prior to re-scan?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Have you previously called StopScan?

    Check the value of Log(LastException) in the disconnected event.
     
  5. megaB4x

    megaB4x Member Licensed User

    manager.StopScan is called in the Manager_DeviceFound.

    Here is the Log(LastException) of the disconnected event:
    B4IExceptionWrapper:Error Domain=CBErrorDomain Code=6 "The connection has timed out unexpectedly" UserInfo=0x17426dc00 {NSLocalizedDescription=Theconnection has timed out unexpectedly.) > -- 09:16:39
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    It seems like a problem in the peripheral device itself. Try to see when this error happens

    Are you calling ReadData many times? ReadData2 will be more efficient.
     
  7. megaB4x

    megaB4x Member Licensed User

    Yes, I am using ReadData2. It appears that same app works fine on iPad with iOS 7.1 whereas it keep disconnecting on iPhone 6 with iOS8.x
    I will research further. Thanks again!
     
  8. fbritop

    fbritop Active Member Licensed User

    Erel,
    If a BLE device goes out of range and the app is in background. Should it reconnect automatically upon coming into range?

    Thanks
    FBP
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this question.
     
Loading...