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

non-connectable advertising while connected on SDK15.3

Hello,

I'm using SDK15.3 and trying to do a non-connectable advertising while connected. 

For that I set my adv package as non-connectable, however, when I run the function sd_ble_gap_adv_start I always receive the error 0x3004.

        case BLE_GAP_EVT_CONNECTED:
            NRF_LOG_INFO("Connected");
            bsp_board_led_on(CONNECTED_LED);
            bsp_board_led_off(ADVERTISING_LED);
            m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
            err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
            APP_ERROR_CHECK(err_code);
            advertising_update();
            advertising_start();
            break;

Based on my research on the forum I know it's possible to do non-connectable advertising while connected, at least in older versions of the SDK. I had a hard time to implement the advertising update in this SDK but now it's working fine, the error occurs simply by calling the function advertising_start while I'm connected.

Does anyone know how to solve this problem?

Thank you very much.

Parents Reply Children
  • As for the error code 7 it means NRF_ERROR_INVALID_PARAM though the only modification I made in the example advertising_init function was to change the BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED to BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED as suggested. I also tried increasing the advertising period to 200ms but the error persists.

  • You will have seen my comments about how unhelpful that error message is!

    Disappointed

  • Hi,

    What exact SoftDevice are you using? S140 v6.1.1?

    Unfortunately NRF_ERROR_INVALID_PARAM from sd_ble_gap_adv_set_configure() may mean several things, but if you share here how and what you fill into the structs used for p_adv_data and p_adv_params I will try to help figure this out.

    Regards,
    Terje

  • Hi,

    I'm using the SDK15.3 softdevice s140 6.1.1

    to illustrate better I did the following. Used the example ble_app_blinky and modified just the parts I'm posting here, the rest of the code I didn't change anything.

    Firstly for the function advertising_init() I just created a parameter to tell if the advertising is of the type connectable or not if it's connectable there's no change related to the original function, otherwise, it changes the type to non-connectable. As follows:

    static void advertising_init(bool connectable)
    {
        ret_code_t    err_code;
        ble_advdata_t advdata;
        ble_advdata_t srdata;
    
        ble_uuid_t adv_uuids[] = {{LBS_UUID_SERVICE, m_lbs.uuid_type}};
    
        // Build and set advertising data.
        memset(&advdata, 0, sizeof(advdata));
    
        advdata.name_type          = BLE_ADVDATA_FULL_NAME;
        advdata.include_appearance = true;
        advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    
    
        memset(&srdata, 0, sizeof(srdata));
        srdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
        srdata.uuids_complete.p_uuids  = adv_uuids;
    
        err_code = ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
        APP_ERROR_CHECK(err_code);
    
        err_code = ble_advdata_encode(&srdata, m_adv_data.scan_rsp_data.p_data, &m_adv_data.scan_rsp_data.len);
        APP_ERROR_CHECK(err_code);
    
        ble_gap_adv_params_t adv_params;
    
        // Set advertising parameters.
        memset(&adv_params, 0, sizeof(adv_params));
    
        if(connectable)
        {
          adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
          adv_params.interval        = APP_ADV_INTERVAL;
        }
        else
        {
          adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;
          adv_params.interval        = 320;
        }
        adv_params.primary_phy     = BLE_GAP_PHY_1MBPS;
        adv_params.duration        = APP_ADV_DURATION;
        adv_params.p_peer_addr     = NULL;
        adv_params.filter_policy   = BLE_GAP_ADV_FP_ANY;
        
        err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &adv_params);
        NRF_LOG_INFO("error code: %x", err_code);
        APP_ERROR_CHECK(err_code);
    }
    

    Later I called the advertisig_init with the corresponding parameter of non-connectable in the BLE_GAT_EVT_CONNECTED as bellow. 

            case BLE_GAP_EVT_CONNECTED:
                NRF_LOG_INFO("Connected");
                bsp_board_led_on(CONNECTED_LED);
                bsp_board_led_off(ADVERTISING_LED);
                m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
                err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
                APP_ERROR_CHECK(err_code);
                err_code = app_button_enable();
                APP_ERROR_CHECK(err_code);
    
                advertising_init(false);
                advertising_start();
                break;
    

    When I run the code and try to connect it returns an error 7 in the function  

    sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &adv_params); 

    Thank you all for the help.

Related