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

BLE CENTRAL: select which peripheral to connect to from the available ones.

Hi all,

I am checking the Uart central and peripheral projects, also the one with usbd and I have one question that may be obvious for you.

How do you select the peripheral to connect to?

I see there is a scan_start function and the NRF_BLE_SCAN_EVT_CONNECTED event but no code to select the peripheral.

I have already implemented a MIDI BLE peripheral with the dk52, now I need the MIDI BLE central. I suppose I would have to print somewhere the available MIDI devices (peripherals) in order to let the user choose which connnect to, am I right?

Thank you in advance,

Manuel

  • Hi,

    The ble_app_uart_c will connect to the first peripheral it finds that is advertising the UUID of the Nordic UART Service(NUS).

    This is done by setting a UUID filter in scan_init(). Snippet:

        err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_UUID_FILTER, &m_nus_uuid);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_UUID_FILTER, false);
        APP_ERROR_CHECK(err_code);

    The scan module supports different types of filters. Snippet:

    /**@brief Types of filters.
     */
    typedef enum
    {
        SCAN_NAME_FILTER,       /**< Filter for names. */
        SCAN_SHORT_NAME_FILTER, /**< Filter for short names. */
        SCAN_ADDR_FILTER,       /**< Filter for addresses. */
        SCAN_UUID_FILTER,       /**< Filter for UUIDs. */
        SCAN_APPEARANCE_FILTER, /**< Filter for appearances. */
    } nrf_ble_scan_filter_type_t;

  • Thank you very much, I will check those other options as well.

    In the final app I thing I'll print the found peripherals so the user can choose among them.

    Regards,

Related