This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Detect link loss with peripheral

Hello, I am trying out my pca10028 board, with s110 and my updated ble_app_uart expample. I am trying to detect a link loss: board advertises as peripheral connects with android device.

After they connect bluetooth is being turned off in the android. In this situation disconnection was detected immediately.

Next procedure was to turn off the android device while in connection. In keil debugger I saw that connection event happens only ~30 seconds after. As I read the questions in the thread I came across answers that firmware detects it automatically and leads to BLE_GAP_EVT_DISCONNECTEDevent. I am lost at this point. Should I implement link-loss service in my code? Is it set by the the master device? How to reduce this time? How to detect link loss in peripheral?

I have tried to explain the situation in a non highly detailed way. If there is lack of infomartion, please let me know. Thank you.

  • Hi

    The time it takes to recognize a link loss is set by the connection supervising timeout period, which is the time it takes before a BLE devices gives up on the link if no packets are received.

    This time is set up as a part of the connection parameters, and you can try to reduce this parameter to make your device more responsive on a link loss. You just have to make sure it's not too small, or the link will not be very stable (it should be at least 6 times your connection interval).

    If you want an even quicker response on a link loss you could have the phone send some data at a regular interval, and take some action in the peripheral if no data is received for a certain amount of time, but this would require the app to be running continuously on the phone.

    Best regards
    Torbjørn

  • Good afternoon, Torbjørn. I am glad that you have answered to my question. Unfortunately, I am not able to shorten the time to detect the disconnection while shortening connection supervisory timeout.The define of it in my code looks like this:

    #define CONN_SUP_TIMEOUT                100   
    

    So, while in connection I turn off my mobile phone (android). Disconnect event in debugger apears only after 30 seconds no matter what is the value of timeout. I have tried to define it as 4ms. Then MCU does not start properly because smallest possibile defined was 100ms, then code is not being executed. So, my guess is that this value is being used and is responsive... What is your oppinion on this? Why it takes 30 seconds to detect that master device is off.

  • Would I be able solve this by adding [link loss service] ?(devzone.nordicsemi.com/.../group__ble__sdk__srv__lls.html)

    If yes. Could you explain me how to implement it?

  • I doubt the link loss service would help you. The link loss service is simply waiting for the disconnect event to occur, and in your case the problem is that the disconnect event doesn't happen soon enough.

    Do you have access to the Nordic sniffer?
    If you do you should be able to check how long it takes for the phone to properly disconnect the link. Most likely the issue is that the Android phone keeps the connection running in the background.

Related