BLE Connection initialization from Central to Peripheral

Hello,

I study the UART Central-Peripheral example (NUS) out of the box based on Visual Code IDE. I would like to understand on the Central part:

Where exactly in code I can see the act of connection initiation and how central device decides to which peripheral

it wants to connect. I use the SDK and Tool-chain v.3.

Thank you in advance.

Andrei

Parents Reply Children
  • Dear Kenneth,

    Thank you for your response to my question. Regarding your propositions, I already finished the Bluetooth Low Energy Fundamentals course and I checked the README pages of Central UART, Peripheral UART and Central role samples.

    I use the Visual Studio Code IDE, as I started my learning of BLE from proposed courses from Nordic Academy: Fundamental and BLE fundamental. Then I wanted to use the Central_UART and Peripherial_UART as the base of my development.

    I also explored the Central Example from the SDK. In Central example I can clearly see using of 

    static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t typestruct net_buf_simple *ad) function which in its turn calls the 
        err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN,
                    BT_LE_CONN_PARAM_DEFAULT, &default_conn); creating the BLE connection to Peripheral role device.
    Unfortunately, in Central_UART example that I want to use as the base of our development I cannot find that easily any function responsible to connection initialization as bt_conn_le_create(). So I would like you to point me how the connection from Central_UART to Peripheral_UART is initialized in code. Please explain how Central_UART decides to which Peripheral it wants to connect? Where in the code this happens? I would like to find in the code bt_conn_le_create() or its equivalent in Central_UART example from the SDK. I use SDK version 3.0.1. 
    Thank you in advance,
    Andrei
  • Hi,

    The central_uart example use the scan module.

    If you want to use the bt api directly check out for instance \zephyr\samples\bluetooth\central\

    In general just search for main.c files that include bt_conn_le_create().

    Kenneth

  • Hi Kenneth,

    I do want to use the central_uart example as a base. So, can you please explain in a few sentences how it is initialize the connection to a peripheral and how it choose which one to connect? Or just point me where it is explained.

    Andrei

  • I found the explanation here:

     https://devzone.nordicsemi.com/guides/nrf-connect-sdk-guides/b/software/posts/building-a-ble-application-on-ncs-sdk---contrasting-to-softdevice-based-ble-applications---part-2-central-role 

    little bit outdated but still relevant.

    In original Central_UART sample application connection is initialized automatically to a Peripheral_UART device matching the filter because of 

    struct bt_scan_init_param scan_init = {
            .connect_if_match = true,
        };

        bt_scan_init(&scan_init);
    Kind regards,
    Andrei
Related