This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Getting the rssi value (on peripheral side) of a phone connected to the peripheral

Dear Sir,

I have connected a phone to a peripheral device using NRFconnect App.

Now I want to know the rssi value of the phone on the peripheral side. 

I want to get the peer address(of the phone) and corresponding rssi value.

I have done the following code for the same.

    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            NRF_LOG_INFO("Connected hrs.");
            NRF_LOG_INFO_ARRAY(p_ble_evt->evt.gap_evt.params.connected.peer_addr.addr,BLE_GAP_ADDR_LEN);
            NRF_LOG_INFO_ARRAY(peak_rssi.peer_addr.addr,BLE_GAP_ADDR_LEN);
           
            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 = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
            APP_ERROR_CHECK(err_code);
            sd_ble_gap_rssi_start(m_conn_handle,1,0);
            
            break;

        case BLE_GAP_EVT_RSSI_CHANGED:
        NRF_LOG_INFO("In BLE_GAP_EVT_RSSI_CHANGED ");
        c_rssi = p_ble_evt->evt.gap_evt.params.rssi_changed.rssi;
        c_addr = p_ble_evt->evt.gap_evt.params.connected.peer_addr;
        NRF_LOG_INFO_ARRAY(p_ble_evt->evt.gap_evt.params.connected.peer_addr.addr,BLE_GAP_ADDR_LEN);
        NRF_LOG_INFO("RSSI = %d ",c_rssi);
        NRF_LOG_INFO("In BLE_GAP_EVT_RSSI_CHANGED End");
        break;

But here two cases are there 

1)case BLE_GAP_EVT_CONNECTED:

2)case BLE_GAP_EVT_RSSI_CHANGED:

In both these cases I am printing the variable  "p_ble_evt->evt.gap_evt.params.connected.peer_addr.addr".(as I want to get the peer address of the phone connected to the peripheral)

In  case BLE_GAP_EVT_CONNECTED: it shows the same address ( after multiple connect-disconnect operations)

But in case BLE_GAP_EVT_RSSI_CHANGED the same variable is changing continuously (even if the device is connected to a phone).

So which will give the correct peer address of the phone?

Since the first one shows almost the stable one, I think I can relay on that. Am I correct?

Then the problem is which variable will give me the correct rssi value of the phone connected to the peripheral?

Please guide me in this and please give answers to 3 questions mentioned above.

Thank you 

Parents
  • Why do you need to know the peer address?

    A BLE (non mesh) connection is only ever 1-to-1 - so there is no need to distinguish different peers in the connection?

  • I am trying to implement the following scenario.

    One periheral

    Multiple phones.

    Each phone tries to connect to the peripheral.

    I want to connect to the one with highest rssi value.

    I was planning to do the following

    Once the advertising start , the initial 30 seconds I will use to collect the addresses of the phones (whoever tries to connect to the peripheral) and their rssi values. (here i will do connect-disconnect operation to get the details, for 30 secs(for example i am taking this value))

    Then sort it and select the one with highest rssi. 

    After 30 seconds when everyone tries to connect I will check the address of each one and will allow only the one whose adddress match with the selected one ( which has the highest rssi value).

    Will you please tell me if there is any other ways to tackle this scenario(if my approach is not good)?

Reply
  • I am trying to implement the following scenario.

    One periheral

    Multiple phones.

    Each phone tries to connect to the peripheral.

    I want to connect to the one with highest rssi value.

    I was planning to do the following

    Once the advertising start , the initial 30 seconds I will use to collect the addresses of the phones (whoever tries to connect to the peripheral) and their rssi values. (here i will do connect-disconnect operation to get the details, for 30 secs(for example i am taking this value))

    Then sort it and select the one with highest rssi. 

    After 30 seconds when everyone tries to connect I will check the address of each one and will allow only the one whose adddress match with the selected one ( which has the highest rssi value).

    Will you please tell me if there is any other ways to tackle this scenario(if my approach is not good)?

Children
No Data
Related