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

Basic BLE Central Listener

Hi All,

Hoping this is straightforward for an intermediate developer.

nRF52840-DK (matched dongle not yet in use), SDK 15.2.0, SES 4.10a (Jlink 6.40), Windows 10.

My end goal is to programatically listen for all advertising/broadcasting BLE devices in range of my nRF52 DevKit board, and query the address and RSSI for all available devices. I'll have a room full of production BLE peripherals, but don't want to have to connect with them to get their signal strength. The nRF Connect software does what I want, but it's all in desktop GUI-land. Instead of coding javascript around the nRF Connect app, I'd prefer to deploy a "BLE Central" build to my DK and UART back to my PC host the detected devices/RSSIs. Easy, right? ;)

After digging through the forums, I didn't find anyone with code available so I gave it a shot to modify the example on my own. Based on some other posts, I started with the ble_app_uart_c example, and I've tried to clear out the whitelist/filters to listen for any/all advertising BLE devices in range. Not a C programmer, but had some success updating the code, just not getting the scan events I'm expecting, and don't know how/when to parse the scan buffer.

Updated scan_init to replace the init_scan connect_if_match and cfg_tag settings with a null init_scan:
nrf_ble_scan_init_t* init_scan = NULL; //rg
err_code = nrf_ble_scan_init(&m_scan, init_scan, scan_evt_handler);

Commented out the nrf_ble_scan_filter_set and nrf_ble_scan_filters_enable in scan_init.

Put a print statement in nrf_ble_scan_default_param_set to verify that I got it right, and I see the defaults being set, including:
p_scan_ctx->scan_params.filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL;

Updated scan_evt_handler to add:
NRF_LOG_INFO("Scan Event ID: %d", p_scan_evt->scan_evt_id);
and I'm getting a steady stream of code 3 "NRF_BLE_SCAN_EVT_NOT_FOUND" events back on the default scan interval.

SO. Given the default scan settings, I don't see why I'm not getting any NRF_BLE_SCAN_EVT_WHITELIST_ADV_REPORT events. Dug some more and found the scan buffer in the watch window, but don't see a Rosetta stone for decoding it, and don't see an obvious candidate to trigger parsing it to send stuff back over UART. Also, just watching the traffic on the m_scan, it looks like I might be getting extended advertising packets that show up in two chunks- think I need to set the connection params to allow ext packets, but not sure if I need to set any other settings as non-default.

Pointers? Thanks!

Related