Can't connect to BLE peripheral using bt_le_set_auto_conn via HCI

I have Thingy:91 dev board. I have flashed hci_lpuart sample to nrf52840 and successfully ran lte_ble_gateway sample. Now in my application I want to connect to the same hard-coded peripheral, address of which I know. I try to use bt_le_set_auto_conn to establish connection, but connection always fails with the message:

[00:07:24.113,311] <dbg> bt_hci_core: hci_event: event 0x3e
[00:07:24.113,342] <dbg> bt_hci_core: hci_le_meta_event: subevent 0x02
[00:07:24.113,342] <dbg> bt_scan: bt_hci_le_adv_report: Adv number of reports 1
[00:07:24.113,464] <dbg> bt_scan: le_adv_recv: D3:6F:83:29:A1:91 (random) event 0, len 26, rssi -47 dBm
[00:07:24.113,464] <dbg> bt_hci_core: bt_hci_cmd_create: opcode 0x200c param_len 2
[00:07:24.113,494] <dbg> bt_hci_core: bt_hci_cmd_create: buf 0x20018974
[00:07:24.113,525] <dbg> bt_hci_core: bt_hci_cmd_send_sync: buf 0x20018974 opcode 0x200c len 5
[00:07:24.113,616] <dbg> bt_hci_core: process_events: count 2
[00:07:24.113,616] <dbg> bt_hci_core: process_events: ev->state 4
[00:07:24.113,647] <dbg> bt_hci_core: send_cmd: calling net_buf_get
[00:07:24.113,647] <dbg> bt_hci_core: send_cmd: calling sem_take_wait
[00:07:24.113,677] <dbg> bt_hci_core: send_cmd: Sending command 0x200c (buf 0x20018974) to driver
[00:07:24.113,708] <dbg> bt_hci_core: bt_send: buf 0x20018974 len 5 type 0
[00:07:24.113,769] <dbg> bt_hci_core: process_events: ev->state 0
[00:07:24.113,800] <dbg> bt_hci_core: hci_tx_thread: Calling k_poll with 2 events
[00:07:24.115,447] <dbg> bt_hci_core: bt_recv_unsafe: buf 0x20018560 len 6
[00:07:24.115,478] <dbg> bt_hci_core: hci_cmd_complete: opcode 0x200c
[00:07:24.115,509] <dbg> bt_hci_core: hci_cmd_done: opcode 0x200c status 0x00 buf 0x20018560
[00:07:24.115,570] <dbg> bt_hci_core: bt_hci_cmd_send_sync: rsp 0x20018974 opcode 0x200c len 1
[00:07:24.115,661] <dbg> bt_id: set_random_address: F7:0B:12:8F:37:44
[00:07:24.115,692] <dbg> bt_hci_core: bt_hci_cmd_create: opcode 0x2005 param_len 6
[00:07:24.115,722] <dbg> bt_hci_core: bt_hci_cmd_create: buf 0x20018974
[00:07:24.115,753] <dbg> bt_hci_core: bt_hci_cmd_send_sync: buf 0x20018974 opcode 0x2005 len 9
[00:07:24.115,814] <dbg> bt_hci_core: process_events: count 2
[00:07:24.115,844] <dbg> bt_hci_core: process_events: ev->state 4
[00:07:24.115,844] <dbg> bt_hci_core: send_cmd: calling net_buf_get
[00:07:24.115,875] <dbg> bt_hci_core: send_cmd: calling sem_take_wait
[00:07:24.115,905] <dbg> bt_hci_core: send_cmd: Sending command 0x2005 (buf 0x20018974) to driver
[00:07:24.115,905] <dbg> bt_hci_core: bt_send: buf 0x20018974 len 9 type 0
[00:07:24.115,966] <dbg> bt_hci_core: process_events: ev->state 0
[00:07:24.115,997] <dbg> bt_hci_core: hci_tx_thread: Calling k_poll with 2 events
[00:07:24.117,675] <dbg> bt_hci_core: bt_recv_unsafe: buf 0x20018560 len 6
[00:07:24.117,706] <dbg> bt_hci_core: hci_cmd_complete: opcode 0x2005
[00:07:24.117,706] <dbg> bt_hci_core: hci_cmd_done: opcode 0x2005 status 0x00 buf 0x20018560
[00:07:24.117,797] <dbg> bt_hci_core: bt_hci_cmd_send_sync: rsp 0x20018974 opcode 0x2005 len 1
[00:07:24.117,828] <dbg> bt_hci_core: bt_hci_cmd_create: opcode 0x200d param_len 25
[00:07:24.117,858] <dbg> bt_hci_core: bt_hci_cmd_create: buf 0x20018974
[00:07:24.117,889] <dbg> bt_hci_core: bt_hci_cmd_send_sync: buf 0x20018974 opcode 0x200d len 28
[00:07:24.117,950] <dbg> bt_hci_core: process_events: count 2
[00:07:24.117,980] <dbg> bt_hci_core: process_events: ev->state 4
[00:07:24.117,980] <dbg> bt_hci_core: send_cmd: calling net_buf_get
[00:07:24.118,011] <dbg> bt_hci_core: send_cmd: calling sem_take_wait
[00:07:24.118,041] <dbg> bt_hci_core: send_cmd: Sending command 0x200d (buf 0x20018974) to driver
[00:07:24.118,041] <dbg> bt_hci_core: bt_send: buf 0x20018974 len 28 type 0
[00:07:24.118,133] <dbg> bt_hci_core: process_events: ev->state 0
[00:07:24.118,164] <dbg> bt_hci_core: hci_tx_thread: Calling k_poll with 2 events
[00:07:24.119,995] <dbg> bt_hci_core: bt_recv_unsafe: buf 0x20018560 len 6
[00:07:24.120,025] <dbg> bt_hci_core: hci_cmd_status: opcode 0x200d
[00:07:24.120,056] <dbg> bt_hci_core: hci_cmd_done: opcode 0x200d status 0x30 buf 0x20018560
[00:07:24.120,117] <wrn> bt_hci_core: opcode 0x200d status 0x30
[00:07:24.120,239] <err> https_client: Failed to connect to D3:6F:83:29:A1:91 (random) (31)

My code looks like this:

bt_addr_le_t addr = {0};
struct bt_conn *conn;

static void ble_ready(int err)
{
LOG_INF("Bluetooth ready, %d", err);

bt_conn_cb_register(&conn_callbacks);

char * addr_str = "D3:6F:83:29:A1:91";
bt_addr_le_from_str(addr_str, "random", &addr);

LOG_INF("Auto connecting");
int err2 = bt_le_set_auto_conn(&addr, &param);
if(err2) {
LOG_ERR("Could not start autoconnect - %d", err);
}
}

My proj.conf has the same Bluetooth settings as in lte_ble_gateway sample:

# Enable Bluetooth stack and libraries
CONFIG_BT=y
CONFIG_BT_H4=y
CONFIG_BT_WAIT_NOP=y
CONFIG_BT_CENTRAL=y
CONFIG_BT_GATT_CLIENT=y
CONFIG_BT_GATT_DM=y
CONFIG_BT_SCAN=y
CONFIG_BT_SCAN_FILTER_ENABLE=y
CONFIG_BT_SCAN_UUID_CNT=1
CONFIG_BT_CREATE_CONN_TIMEOUT=10
CONFIG_BT_HCI=y

I can connect to device If I specify service UUID in scan filters and perform a scan. Also I can connect if I add address to scan filters and perform a scan, but bt_le_set_auto_conn does not work. Please help!

Parents
  • Hi, 

    In the beginning of the trace I can find that it throw an HCI failed to connect:

    [00:07:24.113,311] <dbg> bt_hci_core: hci_event: event 0x3e

    The below means:

    SDC_HCI_OPCODE_CMD_LE_CREATE_CONN = 0x200d,

    2.47 PARAMETER OUT OF MANDATORY RANGE (0x30)
    The Parameter Out Of Mandatory Range error code indicates that a parameter
    value requested is outside the mandatory range of parameters for the given
    HCI command or LMP PDU and the recipient does not accept that value.

    [00:07:24.120,117] <wrn> bt_hci_core: opcode 0x200d status 0x30

    Likely some illegal connection parameters provided, so I would have started looking there.

    Kenneth

  • My connection parameters are nothing out of ordinary. Since I have moved on with CONFIG_BT_FILTER_ACCEPT_LIST and bt_conn_le_create_auto as bt_le_set_auto_conn is being deprecated, I use the same connection params:

    struct bt_le_conn_param conn_param = {
    .interval_max = 15, .interval_min = 15, .latency = 0, .timeout = 800};

    I think you can close this issue.

Reply
  • My connection parameters are nothing out of ordinary. Since I have moved on with CONFIG_BT_FILTER_ACCEPT_LIST and bt_conn_le_create_auto as bt_le_set_auto_conn is being deprecated, I use the same connection params:

    struct bt_le_conn_param conn_param = {
    .interval_max = 15, .interval_min = 15, .latency = 0, .timeout = 800};

    I think you can close this issue.

Children
No Data
Related