Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

how to filter the scanned broadcasters by short name ?

Hi,all

How to filter  the scanned broadcasters by short name ?

I have been set 'CNT' define, and compiled without any errors,and it worked, but the filtering strategy didn't work

My code is as follows:

err_code = nrf_ble_scan_filter_set(&m_scan,SCAN_SHORT_NAME_FILTER,&m_target_periph_short_name);
APP_ERROR_CHECK(err_code);


err_code = nrf_ble_scan_filters_enable(&m_scan,NRF_BLE_SCAN_SHORT_NAME_FILTER,false);
APP_ERROR_CHECK(err_code);

Thanks!

Parents
  • Hi,

    I found this post, and I assume you are trying to do something similar, changing the filter in ble_app_uart_c, except with a short name.
    I am able to reproduce your issue when I try to follow the steps in that post and use a char for the short name.
    When using a short name you need to provide the name and also its length together in a struct, like nrf_ble_scan_short_name_t.
    When I define the short name as a struct in that way, I am able to start scanning.
    How have you defined m_target_periph_short_name?

    It should be something like:

    static const nrf_ble_scan_short_name_t m_target_periph_name = {"Nordic_UART", 11};

  • Hi,

    thank you for your reply.

    i have used "nrf_ble_scan_short_name_t"  struct as the passing parameter,  which is "m_target_periph_short_name".

    my code is consistent with your example.

    my evt function as follows:

    static void scan_evt_handler(scan_evt_t const * p_scan_evt)
    {
    	nrf_gpio_pin_toggle(LED_4);
    	
    	 
        switch(p_scan_evt->scan_evt_id)
        {
    		case NRF_BLE_SCAN_EVT_FILTER_MATCH:
             {
    					  printf("MAC ADDR: %02X%02X%02X%02X%02X%02X   ",
                          p_adv->peer_addr.addr[0],
                          p_adv->peer_addr.addr[1],
                          p_adv->peer_addr.addr[2],
                          p_adv->peer_addr.addr[3],
                          p_adv->peer_addr.addr[4],
                          p_adv->peer_addr.addr[5]
                          );
    						 //RSSI
    					  printf("MATCH RSSI: %d\r\n", p_adv->rssi);
             } break;
             
    	    case NRF_BLE_SCAN_EVT_NOT_FOUND:
    		{
    	            ble_gap_evt_adv_report_t const * p_adv = p_scan_evt->params.p_not_found;
    				if(find_adv_name(p_adv) == NRF_SUCCESS)	
    					 printf("\r\n");
    		}break;
    		// other case ....
    		default:
                 break;
    	}
    }

    i can see "Nordic_UART" it in "NRF_BLE_SCAN_EVT_NOT_FOUND".

     

Reply
  • Hi,

    thank you for your reply.

    i have used "nrf_ble_scan_short_name_t"  struct as the passing parameter,  which is "m_target_periph_short_name".

    my code is consistent with your example.

    my evt function as follows:

    static void scan_evt_handler(scan_evt_t const * p_scan_evt)
    {
    	nrf_gpio_pin_toggle(LED_4);
    	
    	 
        switch(p_scan_evt->scan_evt_id)
        {
    		case NRF_BLE_SCAN_EVT_FILTER_MATCH:
             {
    					  printf("MAC ADDR: %02X%02X%02X%02X%02X%02X   ",
                          p_adv->peer_addr.addr[0],
                          p_adv->peer_addr.addr[1],
                          p_adv->peer_addr.addr[2],
                          p_adv->peer_addr.addr[3],
                          p_adv->peer_addr.addr[4],
                          p_adv->peer_addr.addr[5]
                          );
    						 //RSSI
    					  printf("MATCH RSSI: %d\r\n", p_adv->rssi);
             } break;
             
    	    case NRF_BLE_SCAN_EVT_NOT_FOUND:
    		{
    	            ble_gap_evt_adv_report_t const * p_adv = p_scan_evt->params.p_not_found;
    				if(find_adv_name(p_adv) == NRF_SUCCESS)	
    					 printf("\r\n");
    		}break;
    		// other case ....
    		default:
                 break;
    	}
    }

    i can see "Nordic_UART" it in "NRF_BLE_SCAN_EVT_NOT_FOUND".

     

Children
  • I found a potential issue. The name passed to nrf_ble_scan_filter_set() has to be longer than the name the peripheral is advertising with.

    Try adding something to the end of the name in m_target_periph_short_name. {"Nordic_UART1", 11} as an example.

    In the peripheral device, make sure that it is set up correctly to advertise using a short name. If it is running the sample in ble_peripheral/ble_app_uart, the DEVICE_NAME must be longer than the desired short name, and in advertising_init() you need to change the name_type and add the length. For example:

    init.advdata.name_type = BLE_ADVDATA_SHORT_NAME;
    init.advdata.short_name_len = 11;

  • Thank you for your patient reply.

    Your indecation is effective.

    It has proved feasible to set ".p_short_name" with an extra character after it."Nordic_UART1" as an example.

Related