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

BLE_GAP_EVT_SCAN_REQ_REPORT not working

I'm trying to have an nRF52 DK detect the RSSI value from phones nearby.

In principle, we need to enable scan request notification, then we can collect the rssi value of the phone.

case BLE_GAP_EVT_SCAN_REQ_REPORT:

rssi = p_ble_evt->evt.gap_evt.params.scan_req_report.rssi;

But I'm having problems with both SDK V11 and V15 to enable scan request notification.

I'm using SoftDevice s132 with nRF52DK.

SDK V11: I added the following lines durinhg the initialization (copied from another thread):

uint32_t opt_id = BLE_GAP_OPT_SCAN_REQ_REPORT;
ble_opt_t ble_options;
ble_options.gap_opt.scan_req_report.enable = 1;
ble_stack_init();
err_code = sd_ble_opt_set(opt_id, &ble_options);
But when I added those lines, the device doesn't advertise at all.
It will advertise again once those lines are removed.

SDK V15: I set scan_req_notification to 1 in advertising_init(): adv_params.scan_req_notification = 1;
I used the phone to scan and detect, then pair with the device.
From the terminal I can see those activities(connect, connection secured, etc..
But I don't see any activity at case BLE_GAP_EVT_SCAN_REQ_REPORT in ble_evt_handler.

I would appreciate suggestions to this issue. Thanks.

  • Scan_01.zip

    Enclosed please find the Scan01.zip file.

    Thanks.

  • Hi,

    The scan request notification should be set in the ble_advertising_start function not the ble_advertising_init function as I had previously commented. The reason is that the parameters in the ble_advertising_init function gets overwritten. You can set it like this:

    uint32_t ble_advertising_start(ble_advertising_t * const p_advertising,
                                   ble_adv_mode_t            advertising_mode)
    {
        uint32_t ret;
    
        if (p_advertising->initialized == false)
        {
            return NRF_ERROR_INVALID_STATE;
        }
    
        p_advertising->adv_mode_current = advertising_mode;
    
        memset(&p_advertising->peer_address, 0, sizeof(p_advertising->peer_address));
    
        if (  ((p_advertising->adv_modes_config.ble_adv_directed_high_duty_enabled) && (p_advertising->adv_mode_current == BLE_ADV_MODE_DIRECTED_HIGH_DUTY))
            ||((p_advertising->adv_modes_config.ble_adv_directed_enabled)           && (p_advertising->adv_mode_current == BLE_ADV_MODE_DIRECTED_HIGH_DUTY))
            ||((p_advertising->adv_modes_config.ble_adv_directed_enabled)           && (p_advertising->adv_mode_current == BLE_ADV_MODE_DIRECTED))
           )
        {
            if (p_advertising->evt_handler != NULL)
            {
                p_advertising->peer_addr_reply_expected = true;
                p_advertising->evt_handler(BLE_ADV_EVT_PEER_ADDR_REQUEST);
            }
            else
            {
                p_advertising->peer_addr_reply_expected = false;
            }
        }
    
        p_advertising->adv_mode_current = adv_mode_next_avail_get(p_advertising, advertising_mode);
    
        // Fetch the whitelist.
        if ((p_advertising->evt_handler != NULL) &&
            (p_advertising->adv_mode_current == BLE_ADV_MODE_FAST || p_advertising->adv_mode_current == BLE_ADV_MODE_SLOW) &&
            (p_advertising->adv_modes_config.ble_adv_whitelist_enabled) &&
            (!p_advertising->whitelist_temporarily_disabled))
        {
            p_advertising->whitelist_in_use         = false;
            p_advertising->whitelist_reply_expected = true;
            p_advertising->evt_handler(BLE_ADV_EVT_WHITELIST_REQUEST);
        }
        else
        {
            p_advertising->whitelist_reply_expected = false;
        }
    
        // Initialize advertising parameters with default values.
        memset(&p_advertising->adv_params, 0, sizeof(p_advertising->adv_params));
    
        p_advertising->adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
    
        // Use 1MBIT as primary phy if no phy was selected.
        if (phy_is_valid(&p_advertising->adv_modes_config.ble_adv_primary_phy))
        {
            p_advertising->adv_params.primary_phy = p_advertising->adv_modes_config.ble_adv_primary_phy;
        }
        else
        {
            p_advertising->adv_params.primary_phy = BLE_GAP_PHY_1MBPS;
        }
    
        if (p_advertising->adv_modes_config.ble_adv_extended_enabled)
        {
            // Use 1MBIT as secondary phy if no phy was selected.
            if (phy_is_valid(&p_advertising->adv_modes_config.ble_adv_primary_phy))
            {
                p_advertising->adv_params.secondary_phy = p_advertising->adv_modes_config.ble_adv_secondary_phy;
            }
            else
            {
                p_advertising->adv_params.secondary_phy = BLE_GAP_PHY_1MBPS;
            }
        }
        p_advertising->adv_params.filter_policy = BLE_GAP_ADV_FP_ANY;
    
        // Set advertising parameters and events according to selected advertising mode.
        switch (p_advertising->adv_mode_current)
        {
            case BLE_ADV_MODE_DIRECTED_HIGH_DUTY:
                ret = set_adv_mode_directed_high_duty(p_advertising, &p_advertising->adv_params);
                break;
    
            case BLE_ADV_MODE_DIRECTED:
                ret = set_adv_mode_directed(p_advertising, &p_advertising->adv_params);
                break;
    
            case BLE_ADV_MODE_FAST:
                ret = set_adv_mode_fast(p_advertising, &p_advertising->adv_params);
                break;
    
            case BLE_ADV_MODE_SLOW:
                ret = set_adv_mode_slow(p_advertising, &p_advertising->adv_params);
                break;
    
            case BLE_ADV_MODE_IDLE:
                p_advertising->adv_evt = BLE_ADV_EVT_IDLE;
                break;
    
            default:
                break;
        }
    
        if (p_advertising->adv_mode_current != BLE_ADV_MODE_IDLE)
        {
          p_advertising->adv_params.scan_req_notification = 1;
    
            ret = sd_ble_gap_adv_set_configure(&p_advertising->adv_handle, p_advertising->p_adv_data, &p_advertising->adv_params);
            if (ret != NRF_SUCCESS)
            {
                return ret;
            }
            ret = sd_ble_gap_adv_start(p_advertising->adv_handle, p_advertising->conn_cfg_tag);
    
            if (ret != NRF_SUCCESS)
            {
                return ret;
            }
        }
    
        if (p_advertising->evt_handler != NULL)
        {
            p_advertising->evt_handler(p_advertising->adv_evt);
        }
    
        return NRF_SUCCESS;
    }
    

    Sorry for the confusion.

    Regards

    Jared

  • Thank you. That resolved the issue. Now it's showing the RSSI. But I have a couple more questions. When I have several phones nearby and it showed only one RSSI value. How do I know which phone corresponds to that RSSI? I tried to expand several address indexes and I see the following:

    <info> app: RSSI:-81
    <info> app: PEER[0]: AF
    <info> app: PEER[1]: 04
    <info> app: PEER[2]: 0D
    <info> app: PEER[3]: AF
    <info> app: PEER[4]: 34
    <info> app: PEER[5]: 74
    <info> app: SCAN REPORT SENT
    <info> app: RSSI:-63
    <info> app: PEER[0]: C1
    <info> app: PEER[1]: 04
    <info> app: PEER[2]: 0D
    <info> app: PEER[3]: AF
    <info> app: PEER[4]: 34
    <info> app: PEER[5]: 74
    <info> app: SCAN REPORT SENT
    <info> app: RSSI:-65
    <info> app: PEER[0]: BF
    <info> app: PEER[1]: 04
    <info> app: PEER[2]: 0D
    <info> app: PEER[3]: AF
    <info> app: PEER[4]: 34
    <info> app: PEER[5]: 74

    I wonder what do these addresses mean? Are they the MAC addresses of those phones? To me they don't seem like BT addresses. Too many bytes are similar for the different phones that I have, while the first one keeps changing. It could be that the printout is slower than the scanning process.

    I also observed in many cases it has no response from the phones. It looks like we can only get the RSSI when the phone is scanning for BLE devices. Otherwise we will not get any RSSI from them.

  • Hi,

    vn2000 said:
    I also observed in many cases it has no response from the phones. It looks like we can only get the RSSI when the phone is scanning for BLE devices. Otherwise we will not get any RSSI from them.

     The central has to scan the peripheral that advertises for a SCAN REQUEST event to be made. Otherwise the peripheral will not get the RSSI.

Related