For my application I'd like to have my device (nRF5340) be simultaneously (1) a central with a single peripheral connected, and (2) a peripheral with multiple centrals connected.
To facilitate this I want connectable advertising to continue even after the first connection has been established.
I start advertising with:
static const struct bt_data ad[] = {
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)),
};
static const struct bt_data sd[] = {
BT_DATA_BYTES(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME)
};
...
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad),
sd, ARRAY_SIZE(sd));
And my prj.conf includes:
CONFIG_BT=y CONFIG_BT_PERIPHERAL=y CONFIG_BT_CENTRAL=y CONFIG_BT_MAX_CONN=8 CONFIG_BT_MAX_PAIRED=8 CONFIG_BT_SMP=y CONFIG_BT_CONN_CTX=y CONFIG_BT_SCAN=y CONFIG_BT_SCAN_FILTER_ENABLE=y CONFIG_BT_SCAN_UUID_CNT=1 CONFIG_BT_GATT_CLIENT=y CONFIG_BT_GATT_DM=y
So I have two questions on this:
- Is there a setting in NCS/Zephyr to have advertising not stop upon connection?
- I tried manually restarting advertising in the connection callback (by calling bt_le_adv_start with the same parameters again). But bt_le_adv_start returns -ECONNREFUSED, which according to Zephyr docs happens "When connectable advertising is requested and there is already maximum number of connections established in the controller." Why is this the case when I have CONFIG_BT_MAX_CONN=8? Is this a bug?