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

interactive sd_ble_gap_connect() -> error

Hi Nordic, 

I want to establish a user controlled connection  to a ble_peripheral.  I am using the Sdk 15.3, s140 and the nrf52840.

The idea is: Ble_central show all scanned devices, then based on a command, the user selects to whom it should connect. Similar as the ble_app_interactive idea, but there a bonding is always implemented. 

In our application, with every  BLE_GAP_EVT_ADV_REPORT event, the p_ble_evt->evt.gap_evt.params.adv_report.peer_addr is saved. 

The intention is to use it then with the sd_ble_gap_connect() function. 

  	
  	static ble_gap_conn_params_t const m_connection_param =
{
		NRF_BLE_SCAN_MIN_CONNECTION_INTERVAL,
		NRF_BLE_SCAN_MAX_CONNECTION_INTERVAL,
		NRF_BLE_SCAN_SLAVE_LATENCY,
	    NRF_BLE_SCAN_SUPERVISION_TIMEOUT
};
  	
/**< Scan parameters requested for scanning and connection. */
static ble_gap_scan_params_t const m_scan_param =
{
    .active        = 0x01,
    .interval      = NRF_BLE_SCAN_SCAN_INTERVAL,
    .window        = NRF_BLE_SCAN_SCAN_WINDOW,
    .filter_policy = BLE_GAP_SCAN_FP_WHITELIST,
    .timeout       = SCAN_DURATION_WITELIST,
    .scan_phys     = BLE_GAP_PHY_1MBPS,
};  	
 err_code = sd_ble_gap_connect(&p_ble_evt->evt.gap_evt.params.adv_report.peer_addr,
        			&m_scan_param,
					&m_connection_param,
					APP_BLE_CONN_CFG_TAG);

This returns 07 as an error which is invalid param. 

Is there something  that i'm missing?

In the ble_app_interactive example, the peer_addr is took from the bonding data.  Is this the only possibility?

Thank you in advance. 

Parents
  • I notice you have set BLE_GAP_SCAN_FP_WHITELIST, I believe you should use: BLE_GAP_SCAN_FP_ACCEPT_ALL here.

    As reference you can also checkout the \ble_app_multilink_central example

    Best regards,
    Kenneth

  • hi! 

    in the ble_app_multilink_central example, the sd_ble_gap_connect() fcn is not used. 
    Now i have modified it to be more similar to the ble_app_interactive example. 

    For the scan initialization:

    NRF_BLE_SCAN_DEF(m_scan); 
    
    static ble_gap_conn_params_t const m_connection_param =
    {
    		NRF_BLE_SCAN_MIN_CONNECTION_INTERVAL,
    		NRF_BLE_SCAN_MAX_CONNECTION_INTERVAL,
    		NRF_BLE_SCAN_SLAVE_LATENCY,
    	NRF_BLE_SCAN_SUPERVISION_TIMEOUT
    };
    
    /**@brief Function for initialization Scanning Module.
     */
    static void scan_init(void)
    {
        ret_code_t err_code;
    
        err_code = nrf_ble_scan_init(&m_scan, NULL, NULL);
        APP_ERROR_CHECK(err_code);
    }

    Then, in the ble_evnt_handler:

    	case BLE_GAP_EVT_ADV_REPORT:
    
            if(p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr[0] == 0xA6){ //device i want to connect to
                err_code = sd_ble_gap_connect(&p_ble_evt->evt.gap_evt->params.adv_report.peer_addr,
            			&m_scan.scan_params,
    					&m_connection_param,
    					APP_BLE_CONN_CFG_TAG);
                NRF_LOG_INFO("Connect error %d", err_code);
                }
        break;

    With the previous definitions:

     

    #define NRF_BLE_SCAN_MIN_CONNECTION_INTERVAL 7.5
    #define NRF_BLE_SCAN_MAX_CONNECTION_INTERVAL 50
    #define NRF_BLE_SCAN_SLAVE_LATENCY 5
    #define NRF_BLE_SCAN_SUPERVISION_TIMEOUT 6200
    
    /**@brief Connection parameters requested for connection.
     */
    static ble_gap_conn_params_t const m_connection_param =
    {
    		NRF_BLE_SCAN_MIN_CONNECTION_INTERVAL,
    		NRF_BLE_SCAN_MAX_CONNECTION_INTERVAL,
    		NRF_BLE_SCAN_SLAVE_LATENCY,
    		NRF_BLE_SCAN_SUPERVISION_TIMEOUT
    };

    Is it maybe am error on the peripheral side? In that case i would get a connection timeout or error but not at this point. 

    Any idea?

  • In the multilink example you can find example on how to connect with a target in the nrf_ble_scan_connect_with_target() in nrf_ble_scan.c 

    For instance you need to stop scanning and then call sd_ble_gap_connect().

  • Ok yes, i saw that i was not stooping the scanning before calling the sd_ble_gap_connect().
    Thanks for that!  However, it does not fix the issue. I still get the same error.

    According to the documentation, these are the reason to get an NRF_ERROR_INVALID_PARAM:

    Invalid parameter(s) supplied.

    I made sure that the whitelist is not enabled.  

    How do i set the address in the device identity list? is that necessary? In the interactive example, it's added to while changing the gap privacy settings. 

Reply Children
No Data
Related