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

how to get scan response data

hi i am doing a project where i have to scan for near by ble device using nrf52840 as ble central device,

and connect with customer's ble sensors which have a overparticular adv name. so i decided to use  ble_app_multilink_central example from sdk14.2,

and changed m_target_periph_name[] = "Nordic_Blinky"; to m_target_periph_name[] = "vSensVIOT";

but the central device didn't connected for long time so i tried to debug it and changed it to.

static void on_adv_report(const ble_evt_t * const p_ble_evt)
{
    ret_code_t err_code;
    data_t     adv_data;
    data_t     dev_name;
    bool       do_connect = false;
    const uint8_t mac[] = {0x91,0x49,0xf0,0xf9,0x81,0x00};
    // For readibility.
    ble_gap_evt_t  const * p_gap_evt  = &p_ble_evt->evt.gap_evt;
    ble_gap_addr_t const * peer_addr  = &p_gap_evt->params.adv_report.peer_addr;

    // Initialize advertisement report for parsing
    adv_data.p_data   = (uint8_t *)p_gap_evt->params.adv_report.data;
    adv_data.data_len = p_gap_evt->params.adv_report.dlen;

    if(!memcmp(mac,peer_addr->addr,6))
    {
      NRF_LOG_INFO("FOUND!");
    }
}

and kept one break point in if condition and checked the p_adv_report structure data but i didn't find adv name of sensor,

so i asked customer about it and they said i have to enable active scanning to get adv name.

but in scan parameter i can see that active scanning is already active by default.

but adv name can be seen from nrf connect mobile app.

so tested with some other ble device(esp32) and performed ble scan and i got adv name from that sensor(only when active scanning is enabled).

my question is where can i see active scanning(scan req and scan resp) data.

please help.

Parents
  • Hi Nikunj

    The nRFgo Studio screenshot shows (indirectly) that the name is in the scan response packet, and not in the advertise packet. 

    Both of these packets have 31 bytes available for user data, and as the screenshot shows the two first fields (the 0x01 flag field, and the 0xFF user defined field) take up exactly 31 bytes. This mean the remaining three fields must be found in the scan response packet, including the 0x09 field which has the name. 

    Are you sure you are using the default version of the ble_app_multilink_central example in SDK v14.2.0? 

    I just opened the same example, and found active scanning to be disabled:

    The comment is also a bit different from your screenshot, and your code doesn't write to the .adv_dir_report field. 

    Best regards
    Torbjørn

  • hi ovrebekk,
    thank you  for your response,
    yes you are right the screenshot which i have shared is from "ble_app_blinky_c" example.

    in that the active scanning is but i am not able get adv name from sensor.

Reply Children
  • Hi 

    I tried the ble_app_blinky_c example myself, and I don't seem to have any problem receiving advertising names in either normal adv packets or in scan response packets. 

    Looking closer at the nRF Connect screenshot you sent it appears the advertising name is not "vSensVIOT", but "vSens\0VIOT". 

    For some reason there is a null character in the middle of the name, which I have not seen before, and I don't know how well the strcmp(..) function will work in this case (I know it definitely won't work if you set the m_target_periph_name to "vSensVIOT"). 

    Try to set m_target_periph_name to "vSens\0VIOT", and see if it works better. 

    Best regards
    Torbjørn

  • thank you ovrebekk,

    i found adv name of sensor, when i changed 

    m_target_periph_name[] = "vSensVIOT";

    to 

    m_target_periph_name[] = "vSens\0VIOT"; 

    and in multilink example i changed on_adv_report function to 

    static void on_adv_report(const ble_evt_t * const p_ble_evt)
    {
        ret_code_t err_code;
        data_t     adv_data;
        data_t     dev_name;
        bool       do_connect = false;
    //    static const uint8_t mac_to_find[6] = {0x06,0x15,0xeb,0x22,0x91,0xb0};
    //    static const uint8_t mac_to_find[6] = {0x13,0xbd,0xf2,0x44,0xd1,0x6a};
        static const uint8_t mac_to_find[6] = {0x91,0x49,0xf0,0xf9,0x81,0x00};
    
        // For readibility.
        ble_gap_evt_t  const * p_gap_evt  = &p_ble_evt->evt.gap_evt;
        ble_gap_addr_t const * peer_addr  = &p_gap_evt->params.adv_report.peer_addr;
        
        ble_gap_evt_adv_report_t const *adv_report = &p_ble_evt->evt.gap_evt.params.adv_report;
        
        if((!memcmp(mac_to_find,peer_addr->addr,6)) && adv_report->scan_rsp)
        {
          NRF_LOG_INFO("GOT scan rsp");
        }
    
        else if(!memcmp(mac_to_find,peer_addr->addr,6))
        {
          NRF_LOG_INFO("GOT THE MAC");
        }
      
    }

  • Hi

    I am glad to hear this solved the issue!

    Best of luck with your project Slight smile

    Torbjørn

Related