A few things to preface:
Hardware: nRF52840 Development Kit (PCA10056 - 2.0.1 - 2020.11)
Nordic SDK: nRF5_SDK_17.0.0_9d13099
Central example project I am using: nRF5_SDK_17.0.0_9d13099\examples\ble_central\ble_app_uart_c\pca10056\s140
Ble peripheral device I am trying to communicate with: BLE pressure sensor that sends sensor data as part of it's advertising report.
Hello,
In summary, I am trying to read sensor data from a BLE peripheral device that transmits it's sensor data in advertising packets. I am not trying to establish a connection with the device.
From what I have read online, I have configured the scanner in the following manner:
static ble_gap_scan_params_t scanParams =
{
.extended = 1,
.report_incomplete_evts = 0,
.active = 1,
.filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL,
.scan_phys = BLE_GAP_PHY_1MBPS,
.interval = NRF_BLE_SCAN_SCAN_INTERVAL,
.window = NRF_BLE_SCAN_SCAN_WINDOW,
.timeout = NRF_BLE_SCAN_SCAN_DURATION,
.channel_mask = {0,0,0,0,0},
};
/**
* Initializes the scanning parameters.
*/
void scanningInit(void)
{
ret_code_t errCode;
nrf_ble_scan_init_t initScan;
memset(&initScan, 0, sizeof(initScan));
initScan.connect_if_match = false; // Don't connect on filter match. Only report advertising data
initScan.conn_cfg_tag = BleManagerNrf5::APP_BLE_CONN_CFG_TAG;
// Enable extended advertisement scanning
initScan.p_scan_param = &scanParams;
errCode = nrf_ble_scan_init(&mScanning, &initScan, bleScanEventHandler);
APP_ERROR_CHECK(errCode);
}
I have verified my peripheral device is advertising by using nRFConnect for desktop and the nRF52840 USB dongle to scan as seen below. The data I am interested in is the ServiceData as highlighted in red.

I also captured this data using Wireshark and the provided Nordic BLE sniffer firmware. The ServiceData can be seen in the lower red box below. Also note that there are "60 bytes on wire" which I will get to in a second.

The service data as indicated in the BLE peripheral sensor datasheet is the following format:

So the advertising data I am looking for is 0x0302FF180F16FF188B0000B116647F3897F98100
Where:
0302FF18 = BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_MORE_AVAILABLE (Length 3 bytes)
0F16FF188B0000B116647F3897F98100 = BLE_GAP_AD_TYPE_SERVICE_DATA (Length 15 bytes)
Lastly, this is how I am trying to find this service data in the nRF52840 firmware.
switch (pBleEvt->header.evt_id)
{
case BLE_GAP_EVT_ADV_REPORT:
{
DEBUG_BLE("Advertising report received");
// Initialize advertisement report for parsing.
ble_data_t bleData = pBleEvt->evt.gap_evt.params.adv_report.data;
u8 * p_encoded_data = bleData.p_data;
u16 data_len = bleData.len;
p_encoded_data = bleData.p_data;
data_len = bleData.len;
uint16_t data_offset = 0;
uint16_t parsed_name_len = ble_advdata_search(p_encoded_data,
data_len,
&data_offset,
BLE_GAP_AD_TYPE_SERVICE_DATA);
if(parsed_name_len)
{
DEBUG_BLE("Service data found, length = %d", parsed_name_len);
}
break;
}
}
I get service data for other BLE devices in my area in the firmware, just not for the BLE pressure sensor I am looking for even though I can see it fine in nRFConnect for desktop.
Note: I can use the ble_advdata_search() function to scan for BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME and I get a packet with the correct local name, but the ServiceData and other information is missing.
Questions:
1. Is there something obvious I am doing wrong based on the above?
2. Wireshark says the advertising packet is 60 bytes. Does this mean that it's actually 60 bytes or is this Wireshark combining the advertising data into a single packet for viewing purposes? I thought the advertising packet length was limited to 31 bytes if not using advertising extension?
3. I tried enabling support for advertising extensions as seen above in the "scanParams" structure. I also set NRF_BLE_SCAN_BUFFER to 255 in sdk_config.h. Same results.
4. If Wireshark is capable of capturing and organizing all of the received advertising data into a single structure, can the Nordic SDK / SoftDevice API do this? From what I have seen, the SoftDevice is piecemealing parts of the advertising data to the BLE callback via BLE_GAP_EVT_ADV_REPORT instead of passing up the full data payload that includes everything (Local Name, ServiceData, Flags, Etc).
5. Are scan requests sent by the central for every advertising packet received?
Thanks!
Derek