how to get the RRSI of the central device? i am using sdk 17.1.0 and s140 soft device

static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
uint32_t err_code;

switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
NRF_LOG_INFO("Connected");
err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
APP_ERROR_CHECK(err_code);
m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
sd_ble_gap_rssi_start(m_conn_handle,1,0);
err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
APP_ERROR_CHECK(err_code);
err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_CONN, m_conn_handle, 4);
APP_ERROR_CHECK(err_code);
break;

case BLE_GAP_EVT_DISCONNECTED:
NRF_LOG_INFO("Disconnected");
// LED indication will be changed when advertising starts.
m_conn_handle = BLE_CONN_HANDLE_INVALID;
break;

case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
{
NRF_LOG_DEBUG("PHY update request.");
ble_gap_phys_t const phys =
{
.rx_phys = BLE_GAP_PHY_AUTO,
.tx_phys = BLE_GAP_PHY_AUTO,
};
err_code = sd_ble_gap_phy_update(p_ble_evt->evt.gap_evt.conn_handle, &phys);
APP_ERROR_CHECK(err_code);
} break;

case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
// Pairing not supported
err_code = sd_ble_gap_sec_params_reply(m_conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL);
APP_ERROR_CHECK(err_code);
break;

case BLE_GATTS_EVT_SYS_ATTR_MISSING:
// No system attributes have been stored.
err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0, 0);
APP_ERROR_CHECK(err_code);
break;

case BLE_GATTC_EVT_TIMEOUT:
// Disconnect on GATT Client timeout event.
err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gattc_evt.conn_handle,
BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
APP_ERROR_CHECK(err_code);
break;

case BLE_GATTS_EVT_TIMEOUT:
// Disconnect on GATT Server timeout event.
err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gatts_evt.conn_handle,
BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
APP_ERROR_CHECK(err_code);
break;

case BLE_GAP_EVT_RSSI_CHANGED:
rssi = p_ble_evt->evt.gap_evt.params.rssi_changed.rssi;
break;

default:
// No implementation needed.
break;
}
}

i try to get the rssi of the central device that is my phone but it shows 0xffffcd

  • static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {
    uint32_t err_code;
    ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt; // ADDED BY ME

    switch (p_ble_evt->header.evt_id)
    {
    case BLE_GAP_EVT_CONNECTED:
    NRF_LOG_INFO("Connected");
    err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
    APP_ERROR_CHECK(err_code);
    m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
    err_code = sd_ble_gap_rssi_start(p_ble_evt->evt.gap_evt.conn_handle,BLE_GAP_RSSI_THRESHOLD_INVALID,0); //ADDED BY ME
    APP_ERROR_CHECK(err_code); //ADDED BY ME

    err_code = app_timer_start(my_timer_id,APP_TIMER_TICKS(5000),0); //ADDED BY ME
    APP_ERROR_CHECK(err_code); //ADDED BY ME
    err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
    APP_ERROR_CHECK(err_code);
    err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_CONN, m_conn_handle, 4);
    APP_ERROR_CHECK(err_code);
    break;

    case BLE_GAP_EVT_DISCONNECTED:
    NRF_LOG_INFO("Disconnected");
    // LED indication will be changed when advertising starts.
    m_conn_handle = BLE_CONN_HANDLE_INVALID;
    break;

    case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
    {
    NRF_LOG_DEBUG("PHY update request.");
    ble_gap_phys_t const phys =
    {
    .rx_phys = BLE_GAP_PHY_AUTO,
    .tx_phys = BLE_GAP_PHY_AUTO,
    };
    err_code = sd_ble_gap_phy_update(p_ble_evt->evt.gap_evt.conn_handle, &phys);
    APP_ERROR_CHECK(err_code);
    } break;

    case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
    // Pairing not supported
    err_code = sd_ble_gap_sec_params_reply(m_conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL);
    APP_ERROR_CHECK(err_code);
    break;

    case BLE_GATTS_EVT_SYS_ATTR_MISSING:
    // No system attributes have been stored.
    err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0, 0);
    APP_ERROR_CHECK(err_code);
    break;

    case BLE_GATTC_EVT_TIMEOUT:
    // Disconnect on GATT Client timeout event.
    err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gattc_evt.conn_handle,
    BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
    APP_ERROR_CHECK(err_code);
    break;

    case BLE_GATTS_EVT_TIMEOUT:
    // Disconnect on GATT Server timeout event.
    err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gatts_evt.conn_handle,
    BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
    APP_ERROR_CHECK(err_code);
    break;

    case BLE_GAP_EVT_RSSI_CHANGED:
    rssi = p_ble_evt->evt.gap_evt.params.rssi_changed.rssi;
    break;

    default:
    // No implementation needed.
    break;
    }
    }

    i am trying to get the rssi value when the device is connected i am getting like below will it be in dbm or need to convert to dbm?

    info> app: RSSI: 198
    <info> app: RSSI: 199
    <info> app: RSSI: 202
    <info> app: RSSI: 201
    <info> app: RSSI: 199
    <info> app: RSSI: 196
    <info> app: RSSI: 200
    <info> app: RSSI: 202
    <info> app: RSSI: 198
    <info> app: RSSI: 195
    <info> app: RSSI: 198
    <info> app: RSSI: 197
    <info> app: RSSI: 191
    <info> app: RSSI: 185
    <info> app: RSSI: 191
    <info> app: RSSI: 191
    <info> app: RSSI: 191
    <info> app: RSSI: 186
    <info> app: RSSI: 188
    <info> app: RSSI: 191
    <info> app: RSSI: 190
    <info> app: RSSI: 194
    <info> app: RSSI: 193
    <info> app: RSSI: 194
    <info> app: RSSI: 191
    <info> app: RSSI: 192
    <info> app: RSSI: 191
    <info> app: RSSI: 192
    <info> app: RSSI: 187
    <info> app: RSSI: 192
    <info> app: RSSI: 196
    <info> app: RSSI: 194
    <info> app: RSSI: 183
    <info> app: RSSI: 190
    <info> app: RSSI: 191
    <info> app: RSSI: 195
    <info> app: RSSI: 192
    <info> app: RSSI: 192
    <info> app: RSSI: 192
    <info> app: RSSI: 193
    <info> app: RSSI: 193
    <info> app: RSSI: 205
    <info> app: RSSI: 199
    <info> app: RSSI: 206
    <info> app: RSSI: 194
    <info> app: RSSI: 201
    <info> app: RSSI: 200
    <info> app: RSSI: 198
    <info> app: RSSI: 193
    <info> app: RSSI: 202
    <info> app: RSSI: 199
    <info> app: RSSI: 203
    <info> app: RSSI: 198
    <info> app: RSSI: 200
    <info> app: RSSI: 203
    <info> app: RSSI: 198
    <info> app: RSSI: 199
    <info> app: RSSI: 202
    <info> app: RSSI: 194
    <info> app: RSSI: 194
    <info> app: RSSI: 200
    <info> app: RSSI: 192
    <info> app: RSSI: 193
    <info> app: RSSI: 193
    <info> app: RSSI: 198
    <info> app: RSSI: 195
    <info> app: RSSI: 198
    <info> app: RSSI: 191
    <info> app: RSSI: 199
    <info> app: RSSI: 195
    <info> app: RSSI: 194
    <info> app: RSSI: 190
    <info> app: RSSI: 191
    <info> app: RSSI: 191
    <info> app: RSSI: 192
    <info> app: RSSI: 194
    <info> app: RSSI: 195
    <info> app: RSSI: 195
    <info> app: RSSI: 197
    <info> app: RSSI: 186
    <info> app: RSSI: 188
    <info> app: RSSI: 197
    <info> app: RSSI: 191
    <info> app: RSSI: 185
    <info> app: RSSI: 190
    <info> app: RSSI: 194
    <info> app: RSSI: 199
    <info> app: RSSI: 187
    <info> app: RSSI: 192
    <info> app: RSSI: 187
    <info> app: RSSI: 196
    <info> app: RSSI: 180
    <info> app: RSSI: 199
    <info> app: RSSI: 195
    <info> app: RSSI: 190
    <info> app: RSSI: 198
    <info> app: RSSI: 193
    <info> app: RSSI: 188
    <info> app: RSSI: 199
    <info> app: RSSI: 198
    <info> app: RSSI: 190
    <info> app: RSSI: 191
    <info> app: RSSI: 197
    <info> app: RSSI: 195
    <info> app: RSSI: 198
    <info> app: RSSI: 196
    <info> app: RSSI: 178
    <info> app: RSSI: 178
    <info> app: RSSI: 198
    <info> app: RSSI: 199
    <info> app: RSSI: 199
    <info> app: RSSI: 198
    <info> app: RSSI: 198
    <info> app: RSSI: 198
    <info> app: RSSI: 198
    <info> app: RSSI: 178
    <info> app: RSSI: 195
    <info> app: RSSI: 195
    <info> app: RSSI: 181
    <info> app: RSSI: 194
    <info> app: RSSI: 187
    <info> app: RSSI: 201
    <info> app: RSSI: 200
    <info> app: RSSI: 201
    <info> app: RSSI: 196
    <info> app: RSSI: 187
    <info> app: RSSI: 188
    <info> app: RSSI: 199
    <info> app: RSSI: 201
    <info> app: RSSI: 200
    <info> app: RSSI: 196
    <info> app: RSSI: 196
    <info> app: RSSI: 199
    <info> app: RSSI: 190
    <info> app: RSSI: 201
    <info> app: RSSI: 198
    <info> app: RSSI: 201
    <info> app: RSSI: 196
    <info> app: RSSI: 201
    <info> app: RSSI: 187
    <info> app: RSSI: 199
    <info> app: RSSI: 199
    <info> app: RSSI: 200
    <info> app: RSSI: 198
    <info> app: RSSI: 199
    <info> app: RSSI: 196
    <info> app: RSSI: 198
    <info> app: RSSI: 193
    <info> app: RSSI: 192
    <info> app: RSSI: 200
    <info> app: RSSI: 201
    <info> app: RSSI: 196
    <info> app: RSSI: 195
    <info> app: RSSI: 199
    <info> app: RSSI: 200
    <info> app: RSSI: 188
    <info> app: RSSI: 195
    <info> app: RSSI: 198
    <info> app: RSSI: 193

  • Hi,

    What has the value0xffffcd? How do you get the RSSI and which type does your rss variable have, and how do you print/interpret it? The rssi field in the ble_gap_evt_rssi_changed_t struct is a signed 8 bit integer (int8_t).

    I suggest you do something like this, which should give you correct values (something like "<info> app: RSSI: -33" in the log):

            case BLE_GAP_EVT_RSSI_CHANGED:
            {
                int8_t rssi = p_ble_evt->evt.gap_evt.params.rssi_changed.rssi;
                NRF_LOG_INFO("RSSI: %d", rssi);
            } break;
    

    Values are in dBm.

  • static void timeout_handler(void *timeoutpointer)
    {
                uint8_t rssi;
                uint8_t channel;
    
                uint32_t err_code = sd_ble_gap_rssi_get(m_conn_handle,&rssi,&channel);
                APP_ERROR_CHECK(err_code);
                NRF_LOG_INFO("RSSI: %d", rssi);
    }

    i have initialise the rssi variable as int right?

  • venkatesha kj said:
    i have initialise the rssi variable as int right?

    No, it is not right. You are using uint8_t, which is unsigned. But the data here is signed, so rssi should be int8_t (not starting with "u"). The channel is uint_t, so that is correct.

  • if i want to know the rrsi of the central device when the device was not connected then how do i get that?

Related