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

SCAN REQUEST HELP

 Hello, i am using NRF52840 board with NRF52840 SDK version 15.2 with softdevice 140 Version 6.1. I am using the BLE_NUS_UART_C example and id like to send a scan request to a particular peripheral with uuid  A6F30000-74EB-A788-9CC4-68C594834D10. I redefined the NUS_BASE_UUID macro with the desired uuid in lil-endian however im not sure how to proceed from here. i added the case BLE_GAP_EVT_ADV_REPORT in the ble_evt_handler inside my main but im not sure what else to do. 

Any help would be appreciated, thank you.

Parents
  • Hi,

    So if you have opened \nRF5_SDK_15.2.0_9412b96\examples\ble_central\ble_app_uart_c\, then this example by default will connect to peripheral devices which advertise/scan response with a preconfigured UUID:

    #define NUS_BASE_UUID                   {{0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0, 0x93, 0xF3, 0xA3, 0xB5, 0x00, 0x00, 0x40, 0x6E}} /**< Used vendor specific UUID. */

    In your case you only need to update this BASE UUID, and it will automatically connect to specific peripheral that advertise with that specific UUID in scan response packet.

    But to explain a bit more:

    The UUID is set in ble_nus_c_init() when calling sd_ble_uuid_vs_add().

    In scan_init() the exact filter is set to look for this UUID when calling nrf_ble_scan_filter_set(&m_scan, SCAN_UUID_FILTER, &m_nus_uuid); and nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_UUID_FILTER, false);. 

    In scan_evt_handler() you can receive several events as the BLE scanning module have a match or connect to the device.

    Btw: A scan request is automatically sent when an advertising packet is received, so no special handling for this. You can refer to nrf_ble_scan_on_ble_evt() in nrf_ble_scan.c on how to parse the BLE_GAP_EVT_ADV_REPORT (which include the scan response).

    Best regards,
    Kenneth

Reply
  • Hi,

    So if you have opened \nRF5_SDK_15.2.0_9412b96\examples\ble_central\ble_app_uart_c\, then this example by default will connect to peripheral devices which advertise/scan response with a preconfigured UUID:

    #define NUS_BASE_UUID                   {{0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0, 0x93, 0xF3, 0xA3, 0xB5, 0x00, 0x00, 0x40, 0x6E}} /**< Used vendor specific UUID. */

    In your case you only need to update this BASE UUID, and it will automatically connect to specific peripheral that advertise with that specific UUID in scan response packet.

    But to explain a bit more:

    The UUID is set in ble_nus_c_init() when calling sd_ble_uuid_vs_add().

    In scan_init() the exact filter is set to look for this UUID when calling nrf_ble_scan_filter_set(&m_scan, SCAN_UUID_FILTER, &m_nus_uuid); and nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_UUID_FILTER, false);. 

    In scan_evt_handler() you can receive several events as the BLE scanning module have a match or connect to the device.

    Btw: A scan request is automatically sent when an advertising packet is received, so no special handling for this. You can refer to nrf_ble_scan_on_ble_evt() in nrf_ble_scan.c on how to parse the BLE_GAP_EVT_ADV_REPORT (which include the scan response).

    Best regards,
    Kenneth

Children
Related