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

How to get the scan response datafor the center?

Hi,

I'm using the S132 v6.0 and SDK v15.0 to work with nRF52832. I found the it just get the advertising data. If the device put some data into the scan response, when I use 52832 to scan, how to get the scan response data? Thanks.

Parents
  • Hi,

    You have to do active scanning in order to get the scan response. To do that, simply set the active field of the ble_gap_scan_params_t instance to 1 before you pass it in the call to sd_ble_gap_scan_start(). Then you will get the scan response data in a BLE_GAP_EVT_ADV_REPORT event in the same way as you get normal advertising data. You can see which type it is by checking the type field in the ble_gap_evt_adv_report_t.

Reply
  • Hi,

    You have to do active scanning in order to get the scan response. To do that, simply set the active field of the ble_gap_scan_params_t instance to 1 before you pass it in the call to sd_ble_gap_scan_start(). Then you will get the scan response data in a BLE_GAP_EVT_ADV_REPORT event in the same way as you get normal advertising data. You can see which type it is by checking the type field in the ble_gap_evt_adv_report_t.

Children
  • Does S132v6.0 could do it? I have set the active field of the ble_gap_scan_params_t instance to 1, but I couldn't get the scan response data. The bit scan_response of ble_gap_adv_report_type_t is always 0.

  • That's strange. Have you made sure to configure the peripheral so that it has scan response data (essentially just populate ble_advertising_init_t::srdata)?

  • You should not have to do anything more. Can you upload the code for your advertiser and scanner?

  • static void advertising_init(void)
    {
    
        uint32_t               err_code;
        ble_advertising_init_t init;
    
        uint8_t m_addl_adv_manuf_data[19] = {0xaa,0xbb,0x00,0x00,0xC4,0xF1,0x00,0x0b,0x03,0x01};			
    
        memset(&init, 0, sizeof(init));
    
        ble_advdata_manuf_data_t   manuf_data;	
    		
    		
        manuf_data.data.size          = sizeof(m_addl_adv_manuf_data);
        manuf_data.data.p_data        = &m_addl_adv_manuf_data[2];
    		
        init.advdata.p_manuf_specific_data 	= &manuf_data;		
        init.advdata.flags              		= BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    
        init.srdata.name_type          			= BLE_ADVDATA_FULL_NAME;		
        init.srdata.include_appearance 			= false;
        init.srdata.uuids_complete.uuid_cnt	= sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
        init.srdata.uuids_complete.p_uuids  = m_adv_uuids;	
    		
    	
        init.config.ble_adv_fast_enabled  = true;
    
    	
        init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
    		
        init.config.ble_adv_fast_timeout  = APP_ADV_DURATION;
    
        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);
    							
    }
    
    ble_gap_scan_params_t const m_scan_params =
    {
        .active   = 1,
        .interval = SCAN_INTERVAL,
        .window   = SCAN_WINDOW,
    
        .timeout           = SCAN_DURATION,
        .scan_phys         = BLE_GAP_PHY_1MBPS,
        .filter_policy     = BLE_GAP_SCAN_FP_ACCEPT_ALL,
    
    };
    
    void on_adv_report(ble_gap_evt_adv_report_t const * p_adv_report)
    {
    	
    	printf("scan_response=%04x\r\n",p_adv_report->type);
    	printf("%02x %02x %02x %02x %02x %02x\r\n",p_adv_report->peer_addr.addr[5],
    						   p_adv_report->peer_addr.addr[4],p_adv_report->peer_addr.addr[3],
    						   p_adv_report->peer_addr.addr[2],p_adv_report->peer_addr.addr[1],
    						   p_adv_report->peer_addr.addr[0]);
    
    	if(p_adv_report->peer_addr.addr[5]==0xDE&&p_adv_report->peer_addr.addr[4]==0x88)
    	{
    	     printf("ADV data:\r\n");
    	     for(uint8_t i=0;i<p_adv_report->data.len;i++)
    		printf("%02x ",p_adv_report->data.p_data[i]);
    	     printf("\r\n");	
    	}
    
    	uint32_t ret = sd_ble_gap_scan_start(&m_scan_params, &m_scan_buffer);
    }	

    This is the code for the ble_advertising_init and the scan report.

Related