Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to access scan response data

Hi, I am developing an IoT sensor (peripheral device) using SDK v11.

On my sensor, I have defined an advertising packet that broadcasts the complete local name and a scan response packet that broadcasts manufacturer specific data. Both of these are set as follows:

err_code = ble_advdata_set(&advdata, &scanrsp);
APP_ERROR_CHECK(err_code);

I have also created a central device using a nRF51 development board and firmware based on the "ble_app_multirole_lesc" example project. In my derivative project I have removed all peripheral mode functionality so that it just behaves as a central device, and I have temporarily blocked connections in order to process scan responses.

In my sensor FW, I have added the BLE_GAP_EVT_SCAN_REQ_REPORT case to my on_ble_evt. All I am doing at the moment is triggering an output pin to indicate that the sensor did receive a scan request. I have confirmed that the softdevice in the sensor does in fact raise this event when I start scanning with the central device.

However, I don't see how to access the scan response data on the central device. I tried adding BLE_GAP_EVT_SCAN_REQ_REPORT case to my on_ble_evt but this event is never raised.

My questions:

1) I have assumed that the peripheral soft device automatically sends the scan response upon receiving a scan request, and then sends the BLE_GAP_EVT_SCAN_REQ_REPORT event to the application only after successfully sending the scan response. Is this true? Is there something more I need to do on the peripheral side besides just setting the scan response data as I did above?

2) In the central device, is the scan response data accessible to me when the BLE_GAP_EVT_ADV_REPORT is raised? Or is there another event that I need to respond to?

  • Sorry, I answered my own question. I see now that the ble_gap_evt_adv_report_t data type stores both scan response and advertising data in the data member and indicates which one using the scan_rsp member.

    typedef struct
    {
        ble_gap_addr_t peer_addr; /**< Bluetooth address of the peer device. */
        int8_t rssi; /**< Received Signal Strength Indication in dBm. */
        uint8_t scan_rsp : 1; /**< If 1, the report corresponds to a scan response and the type field may be ignored. */
        uint8_t type : 2; /**< See @ref BLE_GAP_ADV_TYPES. Only valid if the scan_rsp field is 0. */
        uint8_t dlen : 5; /**< Advertising or scan response data length. */
        uint8_t data[BLE_GAP_ADV_MAX_SIZE]; /**< Advertising or scan response data. */
    } ble_gap_evt_adv_report_t;

Related