NRF52840 SDK15.3 ble_advertising_restart_without_whitelist() questions

Good day, sirs

I am trying to imply function that one central device could connect to max 3 devices, only one device active, while switch active device between the three devices.

Now having some problem, pls see below related codes:

void advertising_without_whitelist() {
        uint32_t err_code;
        err_code = ble_advertising_restart_without_whitelist(&m_advertising);
        if (err_code != NRF_ERROR_INVALID_STATE) {
            APP_ERROR_CHECK(err_code);
        }
}

void ble_disconnect(void) {
    ret_code_t ret;
    if (m_conn_handle != BLE_CONN_HANDLE_INVALID) {
        ret_code_t ret;
        ret = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
        if (ret != NRF_ERROR_INVALID_STATE) {
            APP_ERROR_CHECK(ret);
        }
        ble_disable = true;
    } else {
        ret = sd_ble_gap_adv_stop(m_advertising.adv_handle);
        if (ret != NRF_ERROR_INVALID_STATE) {
            APP_ERROR_CHECK(ret);
        }
        ble_disable = true;
    }
}
Firstly I connected one device with Whitelist, then execute advertising_without_whitelist(), RTT Viewer displays  ERROR 18 [NRF_ERROR_CONN_COUNT] as below:
Above error was raised by (void) sd_ble_gap_adv_stop(p_advertising->adv_handle); in  ble_advertising_restart_without_whitelist() of ble_advertising.c. Is it because of before calling sd_ble_gap_adv_stop, I must call sd_ble_gap_disconnect?
I know that advertising_without_whitelist() must not executed while connecting with other device, but if I execute ble_disconnected() firstly, then execute advertising_without_whitelist(), RTT Viewer displays  ERROR 7 [NRF_ERROR_INVALID_PARAM]
I analysised that it was flags_set() in ble_advertising.c of SDK 15.3 returns error
static ret_code_t flags_set(ble_advertising_t * const p_advertising, uint8_t flags)
{
    uint8_t * p_flags = ble_advdata_parse(p_advertising->adv_data.adv_data.p_data,
                                          p_advertising->adv_data.adv_data.len,
                                          BLE_GAP_AD_TYPE_FLAGS);

    if (p_flags != NULL)
    {
        *p_flags = flags;
    }

    return sd_ble_gap_adv_set_configure(&p_advertising->adv_handle, &p_advertising->adv_data, &p_advertising->adv_params);
}
Where I am doing wrong?
What's more, I am using VS Code and makefie coding, is there any good way to debug? In case of my above questions, how could I locate which PARAM INVALID?
During the weekend, I found interesting things that, if I turn off Bluetooth of connected peripheral A, calling advertising_without_whitelist(), without any errors and other peripheral device could be connected without any problems, then turn on Bluetooth of peripheral A,  I accomplished my aiming function of switching out between them.
Another question come up, is there any difference between "turn off Bluetooth of connected peripheral A" and calling sd_ble_gap_disconnect()? why happens so much different result?
  • Hi,

    Above error was raised by (void) sd_ble_gap_adv_stop(p_advertising->adv_handle);

    In ble_service.c line 1061, an error-code is passed to APP_ERROR_CHECK().

    What funnction returned that error-code?

    I don't think it's sd_ble_gap_adv_stop(), since you have a (void) in front of that function call.

    I am trying to imply function that one central device could connect to max 3 devices, only one device active, while switch active device between the three devices.

    Firstly I connected one device with Whitelist, then execute advertising_without_whitelist(

    If you after the first device is connects, then tries to do connectable-advertising by calling advertising_without_whitelist(), then you are trying make 2 active connects.

    This will fail if you in sdk_config.h have NRF_SDH_BLE_TOTAL_LINK_COUNT and NRF_SDH_BLE_CENTRAL_LINK_COUNT set to 1

  • I agree, also noticed that ammend NRF_SDH_BLE_TOTAL_LINK_COUNT and NRF_SDH_BLE_CENTRAL_LINK_COUNT  will solve the first error, thanks.

    But how about second error, why called ble_disconnected(), come up second error?

    and how is the last question, this is my most wanting an answer.

    thanks for your attention.

  • thanks for your help, but still return errors, pls see below details:

    I added "init.config.ble_adv_on_disconnect_disabled = true;" to Advertising_init(),

    and ammend advertising_without_whitelist() as below:

    void advertising_without_whitelist() {
        if (m_conn_handle != BLE_CONN_HANDLE_INVALID) {
            sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
        }
        ble_advertising_restart_without_whitelist(&m_advertising);
    }

    After I call advertising_without_whitelist(), return error 18  [NRF_ERROR_CONN_COUNT] as below:

    you can see that it was "sd_ble_gap_adv_start" of advertising_start() of ble_advertising.c that returns error 18.

    I found below words in ble_gap.h

    * @retval ::NRF_ERROR_CONN_COUNT ..... The limit of available connections has been reached; connectable advertiser cannot be started.
    ............
    SVCALL(SD_BLE_GAP_ADV_START, uint32_t, sd_ble_gap_adv_start(uint8_t adv_handle, uint8_t conn_cfg_tag));
    already disconnected BLE, the connection should be released, why reaches the limit of available  connections?
    In order to save space, I am not prefer to use muti-peripheral link,  pls help me to solve this. thanks a lot.
  • Hi,

    instead of calling ble_advertising_restart_without_whitelist(&m_advertising); right after sd_ble_gap_disconnect(), try calling it in the ble_evt_handler() BLE_GAP_EVT_DISCONNECTED event

Related