BLE Scanner with RSSI and MAC Address

This blog is to give a demo how to scan the ble advertiser and show the RSSI and MAC address in sorting order.

Basically, I used the demo firmware ble_app_blinky example and added the observer role (passive scanner).

static ret_code_t scan_init(dm_ble_scan_t * const p_scan_ctx)
{
        VERIFY_PARAM_NOT_NULL(p_scan_ctx);

/* We expect better performance when using extended advertising/scanning. However, for simplicity this example uses legacy scanning/advertising. */
#ifdef DM_USE_EXTENDED_SCANNING_ADVERTISING
        p_scan_ctx->scan_params.extended      = APP_SCAN_EXTENDED_ENABLED;
#else
        p_scan_ctx->scan_params.extended      = APP_SCAN_EXTENDED_DISABLED;
#endif
        p_scan_ctx->scan_params.active        = APP_SCAN_ACTIVE_DISABLED;
        p_scan_ctx->scan_params.interval      = APP_SCAN_SCAN_INTERVAL;
        p_scan_ctx->scan_params.window        = APP_SCAN_SCAN_WINDOW;
        p_scan_ctx->scan_params.filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL;
        p_scan_ctx->scan_params.timeout       = APP_SCAN_DURATION;
        p_scan_ctx->scan_params.scan_phys     = BLE_GAP_PHY_1MBPS;

// Assign a buffer where the advertising reports are to be stored by the SoftDevice.
        p_scan_ctx->scan_buffer.p_data = p_scan_ctx->scan_buffer_data;
        p_scan_ctx->scan_buffer.len    = sizeof(p_scan_ctx->scan_buffer_data);

        return NRF_SUCCESS;
}
static ret_code_t scan_start(dm_ble_scan_t const * const p_scan_ctx)
{
        VERIFY_PARAM_NOT_NULL(p_scan_ctx);
        ASSERT(!m_scanning_is_start);

        ret_code_t err_code;
        // Start the scanning.
        err_code = sd_ble_gap_scan_start(&p_scan_ctx->scan_params, &p_scan_ctx->scan_buffer);

        // It is okay to ignore this error, because the scan stopped earlier.
        if ((err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_SUCCESS))
        {
                NRF_LOG_ERROR("sd_ble_gap_scan_start returned 0x%x", err_code);
                return (err_code);
        }
        NRF_LOG_INFO("Starting scan.");
        m_scanning_is_start = true;

        return NRF_SUCCESS;
}

I used 3 x nRF52840 DK boards for this demo.

The attached is the HEX file.

3 nRF52840 DK board is running the BLE Advertising + Scanner at the same time.

Yello blacket is advertising report, Bed one is the combined list.

BLE Configuration

The scanner would get the list of the advertisers on every 5 seconds. It would show the MAC address and RSSI value on the terminal.

2 thoughts on “BLE Scanner with RSSI and MAC Address

  1. Hi i’m a student of university and i want to thank you, you have a very nice blog!

    I would ask if i possible to see the full code because i’m having problem to compile it.
    I have modifed blink example but i haven’t a definition of dm_ble_scan_t.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.