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

Related