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

Ble inactivity Timeout

Hello everyone, 

I work on a project with a custom board and e NRF52840 on it. 

I work with the SDK15.2.0, the SoftDevice s140 and FreeRTOS. 

The BLE function well but if the Android App crash the peripheral is still connected. 

I want to know if there is a timeout or a mechanism to detect inactivity on the connection.

Or I must to implement a app timer to do that ?

Thanks in advance for any answer.

Etienne

  • Hi Etienne,

    I want to know if there is a timeout or a mechanism to detect inactivity on the connection.

    All BLE connections have a supervision timeout. If there are no packets within the supervision timeout, the connection will end with the disconnect reason being "timeout". However, the BLE connection will not end just because the Android app crashes, as long as the BLE stack on the Android phone still works.

    Or I must to implement a app timer to do that ?

    Yes. You could add a timeout in your application to check if you get some activity specific to the app you are using (read or writes to a specific characteristic etc), but that would have to be application-specific. It could, for instance, be an app timer as you suggest, which you reset whenever you detect activity from the app, and if not, let it timeout. Then you could disconnect. Alternatively, you could do this with a WDT if you need a full reset for some reason.

    Einar

  • Hi Einar, 

    Firts, thank you for your response. 

    However, the BLE connection will not end just because the Android app crashes, as long as the BLE stack on the Android phone still works.

    If I understand well, the BLE stack on the Android phone still works and sends packets to the peripheral and it is why there is no disconnect event on the nrf side when the Android app crashes? 

    You could add a timeout in your application to check if you get some activity specific to the app you are using (read or writes to a specific characteristic etc), but that would have to be application-specific.

    If I use an app timer, I must reset the timer in every characteristics I have implemented or there is a ble handler where I can put the reset? 

    Thanks

    Etienne

  • Hi Etienne,

    Etienne said:
    If I understand well, the BLE stack on the Android phone still works and sends packets to the peripheral and it is why there is no disconnect event on the nrf side when the Android app crashes? 

    Yes.

    Etienne said:
    If I use an app timer, I must reset the timer in every characteristics I have implemented or there is a ble handler where I can put the reset? 

    Yes, that is my suggestion. The SDK does not have any code explicitly for this case (actually I don't recall seeing this question before), so it is up to you how you want to do it. If you intend to reset, then you can simply use the WDT and reload it regularly if all is good. If not, then you can disconnect in case there is an active connection.

    One thing though, since this is an unusual question. Why do you want to do this? Why is it a problem that the peripheral is connected to the phone even though the Android app has crashed?

  • Hi Einar, 

    One thing though, since this is an unusual question. Why do you want to do this? Why is it a problem that the peripheral is connected to the phone even though the Android app has crashed?

    It is a problem because when the application chrashed the peripheral is still connected and if I want to re launch the App and try to connect to the peripheral I can't. I must do a physical reset by putting off the battery. I need to be capable of reconnect to the peripheral even if the App crashes without putting off the battery. 

    Futhermore, our application is a low power application and if for any reason the peripheral is still connected to a central and doesn't disconnect after few minutes of inactivity (betweend the central and peripheral), the power never goes down and it's not acceptable.

    Thanks, 

    Etienne

  • Hi,

    Etienne said:
    It is a problem because when the application chrashed the peripheral is still connected and if I want to re launch the App and try to connect to the peripheral I can't.

    It seems like a problem with your app, then? Why should you always connect when starting the app, even if there is already an active connection?

    Etienne said:
    Futhermore, our application is a low power application and if for any reason the peripheral is still connected to a central and doesn't disconnect after few minutes of inactivity (betweend the central and peripheral), the power never goes down and it's not acceptable.

    I see. From a BLE perspective, a connection state is not necessarily more power-consuming than advertising. But of course, it could be that other parts of your device consume more power when connect. In that case, using the approach we have discussed makes sense.

Related