Error with Bluetooth HCI function: bt_hci_cmd_send_sync

Hi,

I am developing the nRF52833 DK with NCS v2.00. I am using a function in my source code that reads the current RSSI of the connection. The function, read_conn_rssi (attached below), is taken from the Bluetooth sample, Bluetooth: HCI Power Control. I am getting the following error with the bt_hci_cmd_send_sync function in my code:

<wrn> bt_hci_core: opcode ox1405 status 0x01

Read RSSI err: -5 reason 0x00

I have been trying to find the error & status codes but have not been able to - where can I find them so that I can see what they mean?

Thanks,

Adam

static void read_conn_rssi(uint16_t handle, int8_t *rssi)
{
	struct net_buf *buf, *rsp = NULL;
	struct bt_hci_cp_read_rssi *cp;
	struct bt_hci_rp_read_rssi *rp;

	int err;

	buf = bt_hci_cmd_create(BT_HCI_OP_READ_RSSI, sizeof(*cp));
	if (!buf) {
		printk("Unable to allocate command buffer\n");
		return;
	}

	cp = net_buf_add(buf, sizeof(*cp));
	cp->handle = sys_cpu_to_le16(handle);

	err = bt_hci_cmd_send_sync(BT_HCI_OP_READ_RSSI, buf, &rsp);
	if (err) {
		uint8_t reason = rsp ?
			((struct bt_hci_rp_read_rssi *)rsp->data)->status : 0;
		printk("Read RSSI err: %d reason 0x%02x\n", err, reason);
		return;
	}

	rp = (void *)rsp->data;
	*rssi = rp->rssi;

	net_buf_unref(rsp);
}

Parents
  • Hi

    Error -5 means there is an I/O error in the bt_hci_cmd_send_sync() function. This was also a problem for this user. Please make sure to set these configs to Y, CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=y and CONFIG_BT_HCI_VS_EXT=y.

    It's also a known issue that you'll run into trouble if you try setting the TX power before setting it before the advertising parameters are set.

    Best regards,

    Simon

  •   I'm currently experiencing the Error -5 issue using the latest SDK v2.5.2 despite following your guidance in this thread.

    Do you have any suggestions? I have both of these enabled: 
    CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=y
    CONFIG_BT_HCI_VS_EXT=y

    Here's the error message I'm getting from BT debug logs:
    HCI set TX power err: -5 reason 0x00
    W: opcode 0xfc0e status 0x42

    Here's my full prj.cfg in case that helps:

    # not yet sure if this is helpful, harmful, or just unnecessary
    CONFIG_NCS_SAMPLES_DEFAULTS=y
    
    # to fix v2.5.x floating points in printk() debug prints
    CONFIG_CBPRINTF_FP_SUPPORT=y
    
    # for reading / writing to flash
    CONFIG_FLASH=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    CONFIG_FLASH_LOG_LEVEL_WRN=y
    CONFIG_FLASH_MAP=y
    CONFIG_NVS=y
    CONFIG_NVS_LOG_LEVEL_WRN=y
    CONFIG_MPU_ALLOW_FLASH_WRITE=y
    
    # software resets
    CONFIG_REBOOT=y
    
    # for button, LED, accelerometer
    CONFIG_GPIO=y
    CONFIG_I2C=y
    
    # for printing heap usage stats
    CONFIG_SYS_HEAP_RUNTIME_STATS=y
    
    # for bluetooth (general)
    CONFIG_BT=y
    CONFIG_BT_DEBUG_LOG=y
    
    # for bluetooth (advertising)
    CONFIG_BT_BROADCASTER=y
    CONFIG_BT_DEVICE_APPEARANCE=512
    CONFIG_BT_DEVICE_NAME_DYNAMIC=y
    CONFIG_BT_EXT_ADV=y
    CONFIG_BT_EXT_ADV_MAX_ADV_SET=2
    
    # for bluetooth (tx power control)
    CONFIG_BT_HCI_VS_EXT=y
    CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=y
    
    # for bluetooth (scanning)
    CONFIG_BT_CENTRAL=y
    CONFIG_BT_SCAN=y
    CONFIG_BT_ID_MAX=1
    CONFIG_BT_SCAN_FILTER_ENABLE=y
    CONFIG_BT_SCAN_NAME_CNT=2
    
    # for bluetooth (connecting)
    CONFIG_BT_SMP=y
    CONFIG_BT_SMP_SC_ONLY=n
    CONFIG_BT_SMP_APP_PAIRING_ACCEPT=n
    CONFIG_BT_SMP_ENFORCE_MITM=y
    CONFIG_BT_BONDABLE=n
    
    # for blueooth (GATT)
    CONFIG_BT_GATT_CLIENT=y
    CONFIG_BT_GATT_DM=y
    CONFIG_BT_GATT_DM_DATA_PRINT=y
    
    #CONFIG_BT_L2CAP_TX_MTU=65
    CONFIG_BT_BUF_ACL_RX_SIZE=251
    CONFIG_BT_BUF_ACL_TX_SIZE=251
    CONFIG_BT_L2CAP_TX_MTU=247
    CONFIG_BT_CTLR_DATA_LENGTH_MAX=251

  • Please create a new case where you upload the full debug log and explain your issue in detail. This case is more than a year old and with a much older NCS version than v2.5.2.

    Best regards,

    Simon

  • Thanks Simon. I made a new ticket but I found the solution so I wanted to post it here too:

    I was using an old sample project and long story short, I was using the wrong handle type / passing the wrong handle. 

    Using the code from this sample project worked for me:

    github.com/.../main.c

Reply Children
No Data
Related