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

Switching advertising type

I have seen that the recommended method for switching between connectable and non-connectable advertising is:

    sd_ble_gap_adv_stop()
    ...change advertising structures as needed...
    sd_ble_gap_adv_start()

My app is doing this, and it works. But using sd_ble_gap_adv_start() instead of ble_advertising_start() causes my app to no longer get events to on_adv_evt(). When I try to change to using ble_advertising_start() instead, I get crashes on restarting (works fine starting the first time).

So is there a way to switch between connectable and non-connectable advertising while still getting advertising events?

Parents
  • Ok,

    It looks like sd_ble_gap_adv_start(...) (in ble_advertising.c) returns 0x12 = NRF_ERROR_CONN_COUNT, yes.

    You can see the different return values for this function here.

     

    Are you in a connection when you stop and restart the advertising? The return value for this function says:

    NRF_ERROR_CONN_COUNT: The limit of available connections has been reached; connectable advertiser cannot be started.

    Best regards,

    Edvin

Reply
  • Ok,

    It looks like sd_ble_gap_adv_start(...) (in ble_advertising.c) returns 0x12 = NRF_ERROR_CONN_COUNT, yes.

    You can see the different return values for this function here.

     

    Are you in a connection when you stop and restart the advertising? The return value for this function says:

    NRF_ERROR_CONN_COUNT: The limit of available connections has been reached; connectable advertiser cannot be started.

    Best regards,

    Edvin

Children
  • Yes, I'm connected, because I do this inside the reply to BLE_GAP_EVT_CONNECTED. I stop advertising, then I change all the settings in m_adv_params to the non-connectable settings (including setting type to BLE_GAP_ADV_TYPE_NONCONN_IND), then restart advertising. That could well be the core of the issue--ble_advertising_start() takes the same ble_advertising_t structure as _init(), and that structure doesn't seem to have any place for the advertising parameters that would set non-connectable type.

Related