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

How to get BLE scan result

Hi,

I am using nrf52832 development board with sdk 17.0.2 and S132 softdevice. My requirement is to scan and advertise at the same time. I am using the ble_app_template as a base code and added the  'nrf_ble_scan_init(&m_scan, NULL, NULL)' and ' nrf_ble_scan_start(&m_scan)' functions to test the scanning functionality. But how do I get the scanned devices name and other details? If that is possible, then I need to call it periodically and print it using UART.

Parents
  • Hi,

    Have you added any filter with nrf_ble_scan_filters_enable() and nrf_ble_scan_filter_set() (see for instance <nRF5 SDK>\examples\ble_central\ble_app_hrs_c\main.c)? If so you would get a NRF_BLE_SCAN_EVT_FILTER_MATCH event when the filter matched. I not and you want to get all advertising packets you could handle the BLE_GAP_EVT_ADV_REPORT event. You will get a pointer to a ble_gap_evt_adv_report_t with that event, giving you all the information from the advertising packet.

Reply
  • Hi,

    Have you added any filter with nrf_ble_scan_filters_enable() and nrf_ble_scan_filter_set() (see for instance <nRF5 SDK>\examples\ble_central\ble_app_hrs_c\main.c)? If so you would get a NRF_BLE_SCAN_EVT_FILTER_MATCH event when the filter matched. I not and you want to get all advertising packets you could handle the BLE_GAP_EVT_ADV_REPORT event. You will get a pointer to a ble_gap_evt_adv_report_t with that event, giving you all the information from the advertising packet.

Children
  • I have added the BLE_GAP_EVT_ADV_REPORT case in ble event. I am able to get the sr_data(scan response data) if I make the m_scan_param.active  = 1; but the device is not scanning all the BLE devices.(Note: all my BLE devices have scan response data). It scan's one device multiple times and the other device occasionally. My requirement is that my scanner(BLE) should scan all the nearby devices and get the scan response data, advertisement data, mac addr and device name so that I can manually filter them.

  • Hi,

    There is no way you can control this specifically. The nRF will send a scan request when possible if configured to do so, but this is by nature a bit random, so you may get many scan responses from one device before you receive one from the other (depending on advertising intervals, signal strenght, time on the nRF side etc.). Given enough time you should be able to get a scan response from all active advertisers within range, though.

  • Okay I understood. Can you respond to my requirements which I have mentioned in my recent post?

    My requirement is that my scanner(BLE) should scan all the nearby devices and get the scan response data, advertisement data, mac addr and device name so that I can manually filter them.
  • Yes, that is what I attempted to do. You write that you get scan responses, and then you just have to wait in order to get from all the active scanners that is within range.

    If the question is about what data you can filter on, then you can filter on whatever is in the advertising report (ble_gap_evt_adv_report_t). That is the actual payload of the advertising packet or scan response packet, the address and some other metadata. You can filter on those manually, as you write.

    Just so there is no confusion I would like to stress that the nRF will not filter out multiple packets from the same address, or link the advertisement packet and scan response packet together. So if you need that, you have to do that filtering yourself (BLE address is part of both events).

    If this does not answer the question, then please clarify what it is you need to know.

  • Okay, this is much better. But I have another doubt. I have a BLE advertising device which advertises some information, but the packets doesn't contain mac address, still I am able to get the mac address in the 'p_adv_report->peer_addr.addr'. How's that possible. If the advt packets doesn't have that information from where the stack is getting it?

Related