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

Finding rssi for one device

Hello there,

I have used the nRF52840 DK to find the rssi values of all peripheral devices using the interactive example. I would like to create a command to find the rssi value of a single device. I have found the BLE address of the device that I want to use as the peripheral but would like some assistance piecing everything together. 

I was thinking of using an if statement to say "if the address is "3E:52:82:FF:88:5F", then print the rssi". I am aware that it is not this straight forward. 

My code is as follows and I have included a picture of the command line for the rssi command and the devices command.

Thank you!

static void device_list_print(nrf_cli_t const * p_cli, scanned_device_t * p_device)
{
    for (uint8_t i = 0; i < DEVICE_TO_FIND_MAX; i++)
    {
        if (p_device[i].is_not_empty)
        {
            nrf_cli_fprintf(p_cli, NRF_CLI_NORMAL, "Device/RSSI(in dBm): ");

            char buffer[ADDR_STRING_LEN];
            int_addr_to_hex_str(buffer, BLE_GAP_ADDR_LEN, p_device[i].addr);

            nrf_cli_fprintf(p_cli, NRF_CLI_NORMAL, "%s %s %d\n", buffer,  p_device[i].dev_name, p_device[i].rssi);
           //address: uint8_t addr[BLE_GAP_ADDR_LEN]
           //name: dev_name[DEVICE_NAME_MAX_SIZE]
        }
    }
}

static void rssi_print(nrf_cli_t const * p_cli, scanned_device_t * p_device){
    for (uint8_t i = 0; i < DEVICE_TO_FIND_MAX; i++)
    {
       if (p_device[i].is_not_empty){
            if (uint8_t addr[BLE_GAP_ADDR_LEN] == "3E:52:82:FF:88:5F" ) {
                nrf_cli_fprintf(p_cli, NRF_CLI_NORMAL, "Device/RSSI(in dBm): ");

                char buffer[ADDR_STRING_LEN];
                int_addr_to_hex_str(buffer, BLE_GAP_ADDR_LEN, p_device[i].addr);

                nrf_cli_fprintf(p_cli, NRF_CLI_NORMAL, "%s %s %d\n", buffer,  p_device[i].dev_name, p_device[i].rssi);
            }

            else {
                nrf_cli_fprintf(p_cli, NRF_CLI_NORMAL, "Device/RSSI(in dBm): ");

                char buffer[ADDR_STRING_LEN];
                int_addr_to_hex_str(buffer, BLE_GAP_ADDR_LEN, p_device[i].addr);

                nrf_cli_fprintf(p_cli, NRF_CLI_NORMAL, "%s %s %d\n", buffer,  p_device[i].dev_name, p_device[i].rssi);
            }
        }
    } 
}
    

Parents
  • Hello,

    What is it that you want to print the RSSI value on? The advertisement packets that you scan?

    If that is the case, What SDK version are you using? The reason I ask is that the advertisement reports are located different places in different SDKs. Either way, look for an event called BLE_GAP_EVT_ADV_REPORT. This event typically has an input parameter, p_ble_evt.

    You can find the RSSI of an advertisement packet the following way:

    case BLE_GAP_EVT_ADV_REPORT:
        int8_t rssi = p_ble_evt->evt.gap_evt.params.adv_report.rssi;
        
        
        NRF_LOG_INFO("received an advertisement with RSSI %d", rssi);
        NRF_LOG_INFO("from address: %02x, %02x, %02x, %02x, %02x, %02x", p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr[0],
                                                                         p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr[1],
                                                                         p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr[2],
                                                                         p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr[3],
                                                                         p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr[4],
                                                                         p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr[5]);
        break;

    You can use CLI instead of NRF_LOG_INFO(), but it was easier to just show using the logger module.

    Best regards,

    Edvin

  • Thank you, Edvin! 

    I would like to print the rssi value as a level 0 command on the cli for the devices that come in when the scan is on (without having to connect to the device). I am using SDK version 15.3.0.

Reply Children
Related