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

How to programatically connect to an arbitrary peripheral device

I am using the example ble_app_uart_c, in which the nRF52840 is the central device. Theoretically, I could have more than one peripheral running the Nordic Uart Service (NUS). For this reason, I don't want to automatically establish a connection with the peripheral. How is can the central connect to a peripheral with a specific MAC address programmatically?

Parents
  • Sorry, I see that I didn't add the snippet in my last reply. Sorry about that.

    I was referring to the static char const m_target_periph_name (line 142 in the main.c). You can edit this to is_connect_per_addr instead for to connect to peripherals with a given address instead.

    /**@brief Names which the central applications will scan for, and which will be advertised by the peripherals.
     *  if these are set to empty strings, the UUIDs defined below will be used
     */
    static char const m_target_periph_name[] = "";      /**< If you want to connect to a peripheral using a given advertising name, type its name here. */
    static bool is_connect_per_addr = false;            /**< If you want to connect to a peripheral with a given address, set this to true and put the correct address in the variable below. */
    
    static ble_gap_addr_t const m_target_periph_addr =
    {
        /* Possible values for addr_type:
           BLE_GAP_ADDR_TYPE_PUBLIC,
           BLE_GAP_ADDR_TYPE_RANDOM_STATIC,
           BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE,
           BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE. */
        .addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC,
        .addr      = {0x8D, 0xFE, 0x23, 0x86, 0x77, 0xD9}
    };

    Best regards,

    Simon

Reply
  • Sorry, I see that I didn't add the snippet in my last reply. Sorry about that.

    I was referring to the static char const m_target_periph_name (line 142 in the main.c). You can edit this to is_connect_per_addr instead for to connect to peripherals with a given address instead.

    /**@brief Names which the central applications will scan for, and which will be advertised by the peripherals.
     *  if these are set to empty strings, the UUIDs defined below will be used
     */
    static char const m_target_periph_name[] = "";      /**< If you want to connect to a peripheral using a given advertising name, type its name here. */
    static bool is_connect_per_addr = false;            /**< If you want to connect to a peripheral with a given address, set this to true and put the correct address in the variable below. */
    
    static ble_gap_addr_t const m_target_periph_addr =
    {
        /* Possible values for addr_type:
           BLE_GAP_ADDR_TYPE_PUBLIC,
           BLE_GAP_ADDR_TYPE_RANDOM_STATIC,
           BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE,
           BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE. */
        .addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC,
        .addr      = {0x8D, 0xFE, 0x23, 0x86, 0x77, 0xD9}
    };

    Best regards,

    Simon

Children
No Data
Related