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

Prevent SD from Automatically Advertising after Disconnection

I have an NRF51 board running as a GATT server. Using an iOS application (LightBlue) I connect to the NRF51. If I quit the iOS application then I get a disconnect event and the NRF51 starts to automatically begin advertising again. I do not want the NRF51 to begin advertising again after a disconnection--I intend to put my system to sleep after displaying a little shutdown LED animation. I don't want someone connecting while I am doing this shutdown.

I think I have a workaround where I call sd_ble_gap_adv_stop() in my advertising event handler if the system is shutting down, but is there a way to prevent it from trying to automatically advertising after being disconnected?

Parents
  • I think you must "hack" the ble_advertising.c in order to not restart the advertising on disconnect. The function above is the one starting the advertising with call to

    ble_advertising_start(BLE_ADV_MODE_DIRECTED);
    

    this call you can see in the original ble_app_hrs example. I have replaced it with the code above. The code above calls the registered event handler in main.c, i.e. the on_adv_evt in main.c. It is actually in on_adv_evt that the chip is put to System Off mode with call to sleep_mode_enter(). Before calling sleep_mode_enter(), you can perform your LED operation.

    If you change the ble_advertising.c file, it is a good practice to place it in your project folder, in order to have the library files unmodified.

  • I was under the mistaken impression that your code was destined for the ble event handler for the disconnection event. Placing in ble_advertising.c makes makes your code make sense now--and even better, it works as advertised (pardon the semi-intentional pun).

    Thanks for the help.

    -F

Reply Children
No Data
Related