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

Device Name Missing from Advertising Response

I'm trying to build a quick application to scan for all devices in the vicinity and print out their details (device name, manf data, RSSI, and BLE address). I am parsing the p_scan_evt->params.p_not_found object to do this. It looks like it's working to read manufacturing info and address of all devices, however the packets appear to be missing the device name. The length of the data packet confirms this.

If I scan in the nRF Connect Android app, I am able to verify the same data my nRF52 does, but the raw advertising packet data has additional data. It contains the buffer the nRF52 sees and the device name in addition.

Do I need to issue a scan request from the device? If so how do I do that? I tried to handle the NRF_BLE_SCAN_EVT_SCAN_REQ_REPORT event but I never enter that case.

Any other suggestions?

static void scan_evt_handler(scan_evt_t const * p_scan_evt)
{
    ret_code_t err_code;

    switch(p_scan_evt->scan_evt_id)
    {
         case NRF_BLE_SCAN_EVT_NOT_FOUND:
             device_found(p_scan_evt->params.p_not_found);
             break;

          case NRF_BLE_SCAN_EVT_SCAN_REQ_REPORT:          
              NRF_LOG_INFO("--------------------- SCAN REQ--------------");
              break;
    }
}

  • Hi

    Have you defined a device name, included the device name in your gap_params_init(), and set the advdata.name_type to BLE_ADVDATA_FULL_NAME in your advertising_init()? You can, for example, see the ble_app_uart example for reference as to how to set up your device to advertise with its name.

    If it doesn't appear in your advertising packet after these steps are in order, that means that the advertising packet is filled up, and does not have room for the device name, in which case you will have to either cut some of the advertising data or add scan response data with the additional information (like the device name). The ble_app_uart also includes scan response data as seen in the srdata calls in advertising_init(). You can also check out the BLE service tutorial for details on how to add scan response data to your advertisements.

    Best regards,

    Simon

  • Hi Simon, thanks for the info, that gives me a few things to look into.

    That being said, I'm actually not working on the peripheral device at all just the scanner so I don't have control over what data is being advertised.

    I think the crux of the issue is that I can see all the fields in the nRF Connect Android app, but not with my nRF52 scanner. So the device must be advertising correctly, however I'm unable to read all the data from it correctly.

  • Hi again

    Thank you for specifying. I didn't realize you were developing the scanning device, sorry about that. In that case, you can check out the ble_app_uart_c example, and its ble_evt_handler, which handles the received advertising data.

    If your peripheral and central connect "right away" like the ble_app_uart and ble_app_uart_c examples do, that might be the reason you don't get the scan response, as the devices might connect before a scan response is sent at all. 

    Best regards,

    Simon

  • Hi Simon,

    I'm not seeing in the ble_app_uart_c example's ble_evt_handler where it would be handling received advertising data. Maybe I'm missing something obvious, but could you please be a bit more specific?

    Just for some more info, I'm using SDK 16 and my scanner doesn't ever establish a connection with any device.

  • Hi Daniel

    I'm sorry, I was positive the advertising reports were added in that example by default. Your ble_evt_handler will have to look something like this:

    static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {
        ret_code_t            err_code;
        ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt;
    
    
        switch (p_ble_evt->header.evt_id)
        {
            case BLE_GAP_EVT_ADV_REPORT:
                if (p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr[0] == 0xD3)
                {
                    NRF_LOG_INFO("adv_report from %02x:02x:02x:02x:02x:02x", p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr[0],
                                                                            p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr[1],
                                                                            p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr[2],
                                                                            p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr[3],
                                                                            p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr[4],
                                                                            p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr[5]);
                    uint8_t channel = p_ble_evt->evt.gap_evt.params.adv_report.ch_index;
                    uint16_t len = (uint16_t)p_ble_evt->evt.gap_evt.params.adv_report.data.len;
                    NRF_LOG_INFO("adv_report channel %d, len %d", channel, len);
                    
                    NRF_LOG_INFO("advertisement:");
                    for (uint16_t i=0; i<len; i++)
                    {
                        NRF_LOG_RAW_INFO("%02x", p_ble_evt->evt.gap_evt.params.adv_report.data.p_data[i]);
                        if(i%10 == 0 && i != 0)
                        {
                            NRF_LOG_RAW_INFO("\r\n");
                        }
                        else if(i<len-1)
                        {
                            NRF_LOG_RAW_INFO(":");
                        }
                    }
                    NRF_LOG_RAW_INFO("\r\n");
                }
                break;
    
    
    
    

    Keep in mind that this snippet has been edited to add print into the ble_evt_handler, but it is what I had available at the time. The advertising report (BLE_GAP_EVT_ADV_REPORT) should handle the initial advertisement and the scan response if any.

    Best regards,

    Simon

Related