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

Scanning for beacons - beginner questions

Hello,

I have several questions regarding BLE beaconing and scanning that I feel are pretty basic but I can't seem to find the answer. I have a nRF52840 Dongle that uses the ble_app_beacon example code to send beacon frames. I am able to see it with the Android nRF Connect App.

Now, I would like to use another Dongle to scan for the beacon frames and get the RSSI of my particular beacon. I understand most of the code of the ble_app_uart can be used because it scans for advertisements with a filter, but I have few questions:

  • How should I define m_nus_uuid so that the filter looks for the example beacon ?
  • What part of the code is executed after the advertisement is detected ? I cannot figure out which event is triggered. Should I add a BLE_GAP_EVT_ADV_REPORT case in ble_evt_handler ?

I am using the SDK v15.2 with S140 v6.1.

Thanks !

Parents
  • Hello,

    Yes, that is correct. It is the BLE_GAP_EVT_ADV_REPORT event in nrf_ble_scan.c that is triggered when the device receives an advertisement, which will call nrf_ble_scan_on_adv_report().

    The ble_app_uart_c example, you can see that in sdk_config.h that NRF_BLE_SCAN_FILTER_ENABLE = 1, and NRF_BLE_SCAN_UUID_CNT = 1. This means that the nrf_ble_scan_on_adv_report() will call adv_uuid_compare(), which will look for the UUID of the Nordic UART service (NUS).

    In earlier SDKs, this was done in the main.c file. You can add this event here as well.

    Note that it is a bit difficult to develop on the nRF52840 dongle, as you don't have any debug possibilities. I really recommend you to get an nRF52840 Development Kit (DK) for development. It will save you a lot of trouble.

    BR,

    Edvin

  • Thank you !

    Is adding a snippet of code in ble_evt_handler sufficient or should I also modify the sdk_config.h ? I suppose it should look like something like this :

    case BLE_GAP_EVT_ADV_REPORT:
    
        const ble_gap_evt_adv_report_t * p_adv_report = &p_gap_evt->params.adv_report;
        
        if (adv_uuid_compare(p_adv_report, m_nus_uuid))
        {
            // get RSSI
        }
        break;

    Also, what is the simplest way to declare m_nus_uuid in order that it looks for my beacon instead of the NUS ?

  • Yes. Something like that should work. The RSSI is stored in the adv_report->rssi.

    Try something like:

            case BLE_GAP_EVT_ADV_REPORT:
                const ble_gap_evt_adv_report_t * p_adv_report = &p_gap_evt->params.adv_report;
                NRF_LOG_INFO("BLE_GAP_EVT_ADV_REPORT, rssi = %d", p_adv_report->rssi);
            break;

    But again, development is a lot easier with the DK instead of the dongle.

    BR,

    Edvin

Reply
  • Yes. Something like that should work. The RSSI is stored in the adv_report->rssi.

    Try something like:

            case BLE_GAP_EVT_ADV_REPORT:
                const ble_gap_evt_adv_report_t * p_adv_report = &p_gap_evt->params.adv_report;
                NRF_LOG_INFO("BLE_GAP_EVT_ADV_REPORT, rssi = %d", p_adv_report->rssi);
            break;

    But again, development is a lot easier with the DK instead of the dongle.

    BR,

    Edvin

Children
No Data
Related