RSSI Read Through HCI is always reads as 127

Hi ,

I'm Using nRFconnect SDKV2.3.0 and in the central device i'm jus trying to read RSSI in connnection Callback but it's always reads as 127.


These are my configurations to enable that

prj.confg --> CONFIG_BT_CTLR_ADVANCED_FEATURES=y  and CONFIG_BT_CTLR_CONN_RSSI=y

I added my code snippet regarding rssi read 

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);
}

static uint16_t default_conn_handle;
int read_rssi;

static void connected(struct bt_conn *conn, uint8_t conn_err)
{

	int err;
	char addr[30];
	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	if (conn_err)
	{
		LOG_INF("Failed to connect to %s (%d)", addr, conn_err);

		if (default_conn == conn)
		{
			bt_conn_unref(default_conn);
			default_conn = NULL;

			err = bt_scan_start(BT_SCAN_TYPE_SCAN_ACTIVE);
			if (err)
			{
				LOG_ERR("Scanning failed to start (err %d)",
						err);
			}
		}

		return;
	}

	LOG_INF("Connected: %s", addr);

	static struct bt_gatt_exchange_params exchange_params;

	exchange_params.func = exchange_func;
	err = bt_gatt_exchange_mtu(conn, &exchange_params);
	if (err)
	{
		LOG_WRN("MTU exchange failed (err %d)", err);
	}

	err = bt_conn_set_security(conn, BT_SECURITY_L0); // BT_SECURITY_L2  ->  BT_SECURITY_L0
	if (err)
	{
		LOG_WRN("Failed to set security: %d", err);

		gatt_discover(conn);
	}

	// TODO: theja newly added
	gatt_discover(conn);

	err = bt_scan_stop();
	if ((!err) && (err != -EALREADY))
	{
		LOG_ERR("Stop LE scan failed (err %d)", err);
	}

	read_conn_rssi(default_conn_handle, &read_rssi);
	uint8_t dater[20] = {'\0'};
	sprintf(dater,"Rssi: %d\r\n", read_rssi);
	send_through_uart(dater);
}

Am I missing something?

Related