Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

When are BLE event observers called? Getting disconnection events as fast as possible?

Hi,

I'm working on a custom bootloader based on the one included with SDK 15.

I have a blocking method (i.e. while loop) that runs at the end of the transmission of all the data over BLE. I want to break out of the while loop and throw an error if the device is disconnected while the loop is being executed.

My problem is that ble_evt_handler is not getting called while I'm running that method. My guess is that it is only called after I call sd_app_evt_wait(), but I'm not sure about it. If this is the case, calling it inside the loop wouldn't work for me because I want the loop to be executed as fast as possible. I read in the documentation that sd_app_evt_wait() returns immediately if there's a pending interrupt. Is it possible to fake a pending interrupt?

Another thing I read I could do is to call sd_ble_gap_adv_start() and check the return code. It throws NRF_ERROR_INVALID_STATE if you are already advertising or NRF_ERROR_CONN_COUNT if you are in a connection (and cannot start another advertiser). But this is ugly I think.

How could I go about my problem? Thanks for your help.

Related