Advertisement failing with -12 or -5 whenever NUS server is active.

Hi!

We want our device (B) to be able to act as a NUS server and a NUS client at the same time (talking to another two devices of ours). It can also act as a peripheral to a third party BLE HID device:

(A: Nus server) ---NUS--- (B: Nus client(A), Nus server(C), ble hid) ---NUS--- (C: Nus client (to B))

Unfortunately, whenever our NUS server has an active connection (to C), bt_le_adv_start returns -12 . Sometimes (depending on A's connection state) also -5.

Further information

- We have CONFIG_BT_MAX_CONN=4

- I have tried to increase CONFIG_HEAP_MEM_POOL_SIZE to 8192 (4x the original value)

- bt_conn_foreach gives only one connection, so there are no non-unrefed connections

- If bt_le_adv_start fails, I am retrying every 1 second, with the same result. (From the main loop, not from within bt callbacks.)

- Relevant code can be found at https://github.com/UltimateHackingKeyboard/firmware/tree/host-routing/device/ , especiall prj.conf, bt_conn.c (general connection handling), bt_advertise.c (advertisement handling), nus_server.c

Ideally, I would like B to be able to handle multiple C's and possibly a single Ble HID device at the same time.


Our (slightly simplified) advertisement code is:

#define AD_NUS_DATA                                                                                \
    BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),                          \
        BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),

#define AD_HID_DATA                                                                                \
    BT_DATA_BYTES(BT_DATA_GAP_APPEARANCE, (CONFIG_BT_DEVICE_APPEARANCE >> 0) & 0xff,               \
        (CONFIG_BT_DEVICE_APPEARANCE >> 8) & 0xff),                                                \
        BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),                      \
        BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(BT_UUID_HIDS_VAL),                     \
            BT_UUID_16_ENCODE(BT_UUID_BAS_VAL)),

static const struct bt_data adNusHid[] = {AD_NUS_DATA AD_HID_DATA};

// Scan response packets

#define SD_NUS_DATA BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_VAL),

#define SD_HID_DATA BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),

static const struct bt_data sdNusHid[] = {SD_NUS_DATA SD_HID_DATA};

void BtAdvertise_Start()
{
    int err;
    const char *adv_type_string;

    adv_type_string = "NUS and HID";
    err = bt_le_adv_start(BT_LE_ADV_CONN, adNusHid, ARRAY_SIZE(adNusHid), sdNusHid, ARRAY_SIZE(sdNusHid));
    
    if (err == 0) {
        printk("%s advertising successfully started\n", adv_type_string);
    } else if (err == -EALREADY) {
        printk("%s advertising continued\n", adv_type_string);
    } else {
        printk("%s advertising failed to start (err %d)\n", adv_type_string, err);
    }
}

Zephyr 3.5.99, NCS v2.6.1. (We are in the process of upgrading to 2.8.0, but we are not there yet. If just waiting for the upgrade is a likely solution, please let me know.)

Questions:

- Any idea what I am doing wrong?

- What is the general approach to diagnose problems like these? (I.e., zephyr, specifically ble issues; I still feel quite lost)

Thanks in advance,

Karel

Parents Reply Children
No Data
Related