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

BLE_OBSERVER_PRIO - priorities with Advertising and the Connection State module

SDK 15.3.0; nRF52832

In a previous discussion about continuing to advertise while connected:

The advertisement module will start connectable advertising on BLE_GAP_EVT_DISCONNECT.  So I changed the priority to allow the app to stop the non-connectable advertising before the event gets processed by the advertisement module

and we had:

/*Application needs higher priority than BLE_ADV_BLE_OBSERVER_PRIO in this case */
#define APP_BLE_OBSERVER_PRIO           0                                       /**< Application's BLE observer priority. You shouldn't need to modify this value. */

That allowed only 1 connection - the advertising was not connectable when already connected.

Now, we want to allow multiple connections.

The Multi-Peripheral example uses the Connection State module to manage the multiple connections.

But this is not correctly counting the connections in my application!

With just 1 connection, it says "0 connections" on the BLE_GAP_EVT_CONNECTED event, and "1 connection" on the BLE_GAP_EVT_DISCONNECTED event.

Disappointed

It looks like this is due to the altered priorities - so the Connection State module is not seeing the events until after the application and the advertising modules.

So what is the correct way to manage this ?

  • Hello,

    It looks like this is due to the altered priorities - so the Connection State module is not seeing the events until after the application and the advertising modules.

    Yes, this is the problem. The connection state module use observer priority '0' by default, same as the app in this case, so it's not guaranteed to receive the event first.

    I see two solutions to this. One is to reduce the priority of the advertiser module  (BLE_ADV_BLE_OBSERVER_PRIO), so you can set APP_BLE_OBSERVER_PRIO to '1' or more. The other option is to set the .ble_adv_on_disconnect_disabled flag to prevent the module from automatically starting advertising on disconnect events. You can start advertising when receiving the disconnect event inside your app handler instead.

  • Thanks.

    I went for the 1st option - adjusting priorities.

Related