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

To be in Non-scannable non-connectable mode

Hi, 

I am on SDK 15.2 and NRF52832. I think that I am quite stupid because I do not succeed to be in Non-scannable non-connectable mode.

I tried few stuffs, change directly the line from the ble_advertising_init from ble_advertising library like that : 

p_advertising->adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;

But I am still at the same point. I Have tried also to add these lignes after the ble_advertising_init call in my advertising_init function : 

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

    //We modify few parameters from ble_advertising_init //AKR
m_advertising.adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;
ret = sd_ble_gap_adv_set_configure(&m_advertising.adv_handle, NULL, &m_advertising.adv_params);

But even with these changes, when I use some sniffers, like NRF connect, I can see that I can connect to my device, and I have a scan response. 

Can you help me?

  • Hi

    Please check out the ble_app_beacon example in the SDK, which implements the nonconnectable_nonscannable advertisement correctly. The beacon will not respond to scan requests/advertising requests.

    Best regards,

    Simon

  • Ok I have checked this example. I have done my advertising_init function like that : 

    static void advertising_init(void)
    {
        uint32_t      err_code;
        ble_advdata_t advdata;
        uint8_t       flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;
    
        ble_advdata_manuf_data_t manuf_specific_data;
        memset(m_beacon_info, 0, sizeof(m_beacon_info));
        manuf_specific_data.company_identifier = APP_COMPANY_IDENTIFIER;
        manuf_specific_data.data.p_data = (uint8_t*) m_beacon_info;
        manuf_specific_data.data.size   = APP_BEACON_INFO_LENGTH;
    
        // Build and set advertising data.
        memset(&advdata, 0, sizeof(advdata));
    
        advdata.name_type             = BLE_ADVDATA_FULL_NAME;
        //advdata.flags                 = flags;
        advdata.include_appearance    = false;
        advdata.p_manuf_specific_data = &manuf_specific_data;
        advdata.uuids_complete.uuid_cnt = 0;   // in order to save bytes, we do not advertise UUID's
        advdata.uuids_complete.p_uuids  = m_adv_uuids;
    
        // Initialize advertising parameters (used when starting advertising).
        memset(&m_advertising.adv_params, 0, sizeof(m_advertising.adv_params));
    
        //FAST
        #if BEACON_MODE && !BEACON_MODE_TEST
           m_advertising.adv_modes_config.ble_adv_fast_enabled  = false;
        #else
           m_advertising.adv_modes_config.ble_adv_fast_enabled  = true;
        #endif
           m_advertising.adv_modes_config.ble_adv_fast_interval = NON_CONNECTABLE_ADV_INTERVAL;
           m_advertising.adv_modes_config.ble_adv_fast_timeout  = APP_ADV_DURATION;
    
    	//SLOW
    	#if BEACON_MODE && !BEACON_MODE_TEST
           m_advertising.adv_modes_config.ble_adv_slow_enabled = true;
    	#else
           init.config.ble_adv_slow_enabled = false;
    	#endif
    		m_advertising.adv_modes_config.ble_adv_slow_interval = NON_CONNECTABLE_ADV_INTERVAL;
    		m_advertising.adv_modes_config.ble_adv_slow_timeout  = APP_ADV_DURATION;
    
        m_advertising.adv_mode_current               = BLE_ADV_MODE_IDLE;
        m_advertising.conn_cfg_tag                   = BLE_CONN_CFG_TAG_DEFAULT;
        m_advertising.evt_handler                    = on_adv_evt;
        m_advertising.current_slave_link_conn_handle = BLE_CONN_HANDLE_INVALID;
        m_advertising.adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;
        m_advertising.adv_params.p_peer_addr     = NULL;    // Undirected advertisement.
        m_advertising.adv_params.filter_policy   = BLE_GAP_ADV_FP_ANY;
        m_advertising.adv_params.interval        = NON_CONNECTABLE_ADV_INTERVAL;
        m_advertising.adv_params.duration        = 0;       // Never time out.
    
        // Copy advertising data.
        if (!m_advertising.initialized)
        {
            m_advertising.adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET;
        }
        m_advertising.adv_data.adv_data.p_data = m_advertising.enc_advdata;
    
        m_advertising.adv_data.adv_data.len = BLE_GAP_ADV_SET_DATA_SIZE_MAX;
        err_code = ble_advdata_encode(&advdata, m_advertising.enc_advdata, &m_advertising.adv_data.adv_data.len);
        APP_ERROR_CHECK(err_code);
    
        //scan data to NULL
        m_advertising.adv_data.scan_rsp_data.p_data = NULL;
        m_advertising.adv_data.scan_rsp_data.len    = 0;
    
        err_code = sd_ble_gap_adv_set_configure(&m_advertising.adv_handle, &m_advertising.adv_data, &m_advertising.adv_params);
        APP_ERROR_CHECK(err_code);
    
        m_advertising.initialized = true;
    }

    I have no errors with the two functions, encode, and sd configure, but I cannot see my device. 

    Can you check my code and tell me if it is correct ?

  • Hi

    I see that you have commented out the advdata.flags. You need advertising flags as part of your advertisement according to the Bluetooth Spec.

    If you just need NONCONNECTABLE_NONSCANNABLE advertising, I suggest basing your application on the beacon example, instead of trying to modify one of the others to do that. 

    Best regards,

    Simon

  • I see that you have commented out the advdata.flags. You need advertising flags as part of your advertisement according to the Bluetooth Spec.

    I have uncommented it, no changes. 

    If you just need NONCONNECTABLE_NONSCANNABLE advertising, I suggest basing your application on the beacon example, instead of trying to modify one of the others to do that. 

    I did that, i have copied the code from the Beacon example, the advertising_init, but I had errors on the encode et sd_configure. I need others pieces of code, so I cannot take all the code from this example. 

  • Hi

    Can you explain what exactly you'd like to achieve so that I know what assistance you need? Also, please explain the following in your advertising_init() function:

    • Have you checked (by debugging) that the FAST and SLOW if-loops you are using are executed as expected in your init function?
    • What are you using the "Copy advertising data" function for exactly?

    Best regards,

    Simon

Related