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

Refer to nordic ble central mutilink to modify zephyr ble connect, disconnection will cause problems (on nrf52840)

Since Zephyr’s official BLE sample code, his BLE central only supports one central to one peripheral
So I refer to the BLE central multulink officially provided by nordic to modify the zephyr example
The reference files are:
\nRF5SDK160098a08e2\examples\ble_central\ble_app_multilink_central

In addition, I also refer to other people’s examples of implementing one central to multiple peripherals
I referred from here https://github.com/zephyrproject-rtos/zephyr/issues/21552
I think his writing is very similar to the logic of Nordic’s BLE central multilink
I use this to modify, central will go to scan peripherals, after subscribing, in the notify function will receive the data sent by the peripheral, received and immediately use bt_gatt_write to send back to the peripheral directly
When I have more than two peripherals links, one of the peripherals is disconnected, it will print [UNSUBSCRIBED] and jump to the disconnect callback function, then clear the disconnected link, then do attempt_scan()
However, the connected peripheral cannot send the data to the central at this time, and the central will be stuck in the attempt_scan() of disconnect, and the transmission can only continue after the central finds(or connects again) the disconnected peripheral again
In theory, in central, disconnected peripherals will not affect the connected peripherals. Did I use the wrong method?
How to prevent central from getting stuck in diconnect's attempt_scan() so that the connected peripheral can still send information to central?

The disconnected callback function as follow:

static void disconnected(struct bt_conn *conn, u8_t reason)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

    u8_t conn_index = bt_conn_index(conn);
    if (conn_index == connecting_index) {
        connecting_index = -1;
        is_connecting = false;
    }
    printk("Disconnected: %s, index: %u, ref: %u, (reason 0x%02x)\n", addr, conn_index, conn->ref, reason);

    if (conn_index < 32) {
        if (connections[conn_index] == conn) {
            bt_conn_unref(connections[conn_index]);
            connections[conn_index] = NULL;
            conn_num--;
        }
    }

    attempt_scan();
}

Thanks in advance,

PYL

Parents
  • Hello,

    If you want to support multiple connections in a zephyr project, you should set the CONFIG_BT_MAX_CONN in prj.conf to whatever number you want to support. Look at how this is set to 1 in the NCS\nrf\samples\bluetooth\peripheral_uart\prj.conf.

    Other than that, you shouldn't mix source code from the nRF5 SDK and nRF Connect SDK (zephyr). They are not compatible.

    The application in the peripheral_uart example is intended for only one connection, but you can look at the peripheral_hids_mouse example, which supports two connections, how you can handle multiple connections from your main.c file.

    the peripheral_uart example has one pointer to the connection:

    static struct bt_conn *current_conn;
    while the peripheral_hids_mouse example has an array:
    static struct conn_mode {
    	struct bt_conn *conn;
    	bool in_boot_mode;
    } conn_mode[CONFIG_BT_HIDS_MAX_CLIENT_COUNT];
    Best regards,
    Edvin
  • Hello,
    CONFIG_BT_MAX_CONN, I have already set it.
    In addition, I did not mix nRF5 SDK and nRF Connect SDK (zephyr) together
    I referred to the process of nrf5 sdk BLE multilink to make changes, sorry I didn’t make it clear
    What is your version of zeohyr? I’m 2.4.99 and I didn’t see the folder peripheral_hids_mouse you mentioned, and I want to use a one central to multiple peripherals
    Thank,

    PoYi,Lin

  • I use NCS (nRF Connect SDK) v1.4.0. Try that one. You can find it here:

    https://github.com/nrfconnect/sdk-nrf

    The sample is found in the path:

    NCS\nrf\samples\bluetooth\peripheral_hids_mouse

    Best regards,

    Edvin

  • Thank you for your offer
    But I currently want to do multilink on central
    And it’s like only peripherals code
    Is there an example of central multilink?

    Thanks,

    Poyi

Reply Children
Related