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

How to set non-connectable mode in BLE

I am trying to change after 10 seconds into non-connectable mode. I am using the below code for initializing:

static void advertising_init(void)
{

    ret_code_t             err_code;
    ble_advertising_init_t init;
    uint8_t       flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    ble_advdata_manuf_data_t manu_data;

    memset(&init, 0, sizeof(init));

    uint8_t data[23]; 

    data[0] = 0x02;
    data[1] = 0x15;

//    memcpy(&data[2],ib_uuid,16);
//    memcpy(&data[18],ib_major,2);
//    memcpy(&data[20],ib_minor,2);

//    memcpy(&data[2],ib_uuid,16);
//    memcpy(&data[18],major_value_global,2);
//    memcpy(&data[20],minor_value_global,2);

    memcpy(&data[2],UUID_global,16);
    data[19] = major_value_global & 0x00FF; 
    data[18] = (major_value_global & 0xFF00) >> 8;

    data[21] = minor_value_global & 0x00FF; 
    data[20] = (minor_value_global & 0xFF00) >> 8;

    data[22] = 0xCE;

    manu_data.company_identifier  = 0X004C;
    manu_data.data.p_data         = data;
    manu_data.data.size           = sizeof(data);

    //ibeacon
    init.advdata.flags                  = flags;
    init.advdata.p_manuf_specific_data  = &manu_data;
    
    uint32_t adv_interval_temp = (adv_interval_time_global * 100) / 0.625;  //Since the adv_interval_time_global is now a value of multiplier.

    init.config.ble_adv_fast_enabled  = true;
    init.config.ble_adv_fast_interval = adv_interval_temp;

    init.evt_handler = on_adv_evt;

    err_code = ble_advertising_init(&m_advertising, &init);
    APP_ERROR_CHECK(err_code);

    ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
}

I want to change mode into non-connectable using this type of advertisement method only atm.

  • Hi, 

    You can refer to \examples\ble_peripheral\ble_app_beacon on how to setup BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED.

    -Amanda H.

  • Thank you for the prompt response.

    Actually the ble_app_beacon uses a different approach to setup the Beacon mainly using:

    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 = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params);
    APP_ERROR_CHECK(err_code);

    This uses the adv_params in which the mode is fed but how can I achieve this by using:

    err_code = ble_advertising_init(&m_advertising, &init);

    As I also have to use:

    ret_code = ble_advertising_advdata_update(&m_advertising, &new_data, true);

    To switch between packets.

Related