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 

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Am I missing something?

Parents
  • Hi,

    In this snippet I do not see that you set default_conn_handle to a sensible value anywhere. Did you not just include that code, or is this uninitialized? You can use bt_hci_get_conn_handle() to get the handle.

  • Hi Einar,

    Thanks for the advise. In fact, I had tried that one as well by getting conn_handle in the connection callback, but the issue remains the same.

  • Hi,

    I see the same on my end now. You cannot do it in the connected callback, but need to wait until that has returned. When I do it from the main loop, I get correct readings using the same code as you use, plus this way to get the default conn handle that I added in the connected callback (default_conn_handle is a uint16_t that is declared on the outside):

    Fullscreen
    1
    2
    3
    4
    5
    int rc = bt_hci_get_conn_handle(conn, &default_conn_handle);
    if(rc)
    {
    printk("fail getting conn handle");
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Reply
  • Hi,

    I see the same on my end now. You cannot do it in the connected callback, but need to wait until that has returned. When I do it from the main loop, I get correct readings using the same code as you use, plus this way to get the default conn handle that I added in the connected callback (default_conn_handle is a uint16_t that is declared on the outside):

    Fullscreen
    1
    2
    3
    4
    5
    int rc = bt_hci_get_conn_handle(conn, &default_conn_handle);
    if(rc)
    {
    printk("fail getting conn handle");
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Children