My use case: There are different but similar peripherals advertising with 1M uncoded or coded PHY. Some of them are even advertising in mixed mode.
Question: How to connect to each of them with my central?
What I did until now: I initialized scanning like that:
struct bt_le_scan_param scan_param = {
.type = BT_LE_SCAN_TYPE_ACTIVE,
.interval = BT_GAP_SCAN_FAST_INTERVAL,
.window = BT_GAP_SCAN_FAST_WINDOW,
.options = BT_LE_SCAN_OPT_CODED
};
struct bt_scan_init_param scan_init = {
.connect_if_match = 0,
.scan_param = &scan_param,
.conn_param = NULL
};
bt_scan_init(&scan_init);
I could verify that my central is receiving both coded and uncoded advertising.
When I decide to connect to one of these peripherals I assumed that I have to initialize connection the same way:
struct bt_conn_le_create_param create_param =
BT_CONN_LE_CREATE_PARAM_INIT(
BT_CONN_LE_OPT_CODED,
BT_GAP_SCAN_FAST_INTERVAL,
BT_GAP_SCAN_FAST_WINDOW
);
struct bt_le_conn_param conn_param = BT_LE_CONN_PARAM_INIT(16, 16, 0, 400);
// addr AND _currentConnection has been previously defined
int error =
bt_conn_le_create(&addr, &create_param, &conn_param, &_currentConnection);
But that leads to an error -5 (I/O error) when calling bt_conn_le_create. In this case there is a log warning
bt_hci_core: opcode 0x2043 status 0x12
I am only able to connect if I explicitly set "BT_CONN_LE_OPT_CODED | BT_CONN_LE_OPT_NO_1M" or "BT_CONN_LE_OPT_NONE" as option of the bt_conn_le_create_param struct. It seems that the SDK is not choosing the appropriate settings automatically.
Is this expected behavior? Do I miss some config or anything else? Or do I have to parse the bt_scan_device_info and setup the connection create parameter dependent to the received phy in bt_scan_device_info?
Regards,
Oliver