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
  • Hi awneil!

    Thank you very much for your prompt help.

    I spent some time trying to make it work but it didn't. Actually this is the approach I was trying to before.

    As far as I understood the SDK15 returns an error when I call the function sd_ble_gap_adv_set_configure, which is necessary to change the advertising to non-connectable, inside the BLE_GAP_EVT_CONNECTED it returns the error code 7.

    I've gone through this same problem when trying to update the contents of the advertising package, but in that case, I found a workaround in the forum where there was no need to call the function sd_ble_gap_adv_set_configure. For the current problem it does not work.

    Thank you.

  • Hi,

    i did the demo at https://github.com/jimmywong2003/nrf5-modify-device-parameter-through-host.

    the device can do the connectable adv  with mobile for parameter change. Also it does the non-connectable adv as beacon adv.

  • Hi,

    You still prepare and send in scan response data (see the srdata variable), which is not needed when you do non-scannable advertising. I do not have time to test now, but I suspect that might give invalid parameter error.

    Edit: Removed paragraph mentioning static memory for advertising data, as I realized you used static memory for that.

    Regards,
    Terje

  • I do not have time to test now, but I suspect that might give invalid parameter error.

    Yes, I think this error code includes, "this particular combination of parameters is not allowed" ? 

  • Hi,

    I tested here and it worked! In that case I changed the advertising type to a scannable one and that passed.

    I needed to update the other part of the code as well so for reference I'm posting the updated code here.

    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_SCANNABLE_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);
    }
    
    //---------------------------------
    
    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;
    
    case BLE_GAP_EVT_DISCONNECTED:
        NRF_LOG_INFO("Disconnected");
        bsp_board_led_off(CONNECTED_LED);
        m_conn_handle = BLE_CONN_HANDLE_INVALID;
        err_code = app_button_disable();
        APP_ERROR_CHECK(err_code);
    
        advertising_stop();
        advertising_init(true);
        advertising_start();
        break;

    Thank you all for your help!

Reply Children
No Data
Related