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

Example use of sd_ble_gap_scan_start

I need to scan for nearby beacons. This was featured in the mbed examples but does not seem to be described anywhere else

I am using SDK12 at the moment.

I found the definition of this API but cannot find any example of its use

Is there one published anywhere? thx.

Parents
  • You don't need to connect to get the BLE address of the beacons. The BLE address is part of the advertising packet, and you can access when you get the event BLE_GAP_EVT_ADV_REPORT.

    Looking at the function ble_evt_handler in the ble_app_uart_c example, you can just comment out the connect request(sd_ble_gap_connect()), and then print the BLE address:

    NRF_LOG_INFO("Beacon address: %02x%02x%02x%02x%02x%02x",
             p_adv_report->peer_addr.addr[0],
             p_adv_report->peer_addr.addr[1],
             p_adv_report->peer_addr.addr[2],
             p_adv_report->peer_addr.addr[3],
             p_adv_report->peer_addr.addr[4],
             p_adv_report->peer_addr.addr[5]
             );
    

    You can also remove the is_uuid_present() function to be able to scan beacons that dont have the NUS UUID present in the ADV packet.

    You should be able to do this with a BLE peripheral example also, but it will require some work to add all the BLE central specific files to the project. But if you need an example that is both BLE central and BLE peripheral you should take a look at the ble_central_and_peripheral examples in the ble_central_and_peripheral folder.

  • Works great thx @Sigurd. I'll leave as a central for now.

Reply Children
No Data
Related