regarding getting RSSI value before the sd_ble_gap_connect requesting

Hi,

       I am using ble_app_uart_c code for connecting with the app. this code act as central and scan the peripheral devices when the UUID matches it get connect with the device.

I am using nrf52840 dongle segger program and my peripheral devices is my mobile.

But for my project  once the UUID matches i need to check the RSSI strength and then connect with the devices so before the sd_ble_gap_connect() occurs  how can i check the signal strength of the UUID matched devices.  Please give some idea how to get the RRSI along with UUID values in the Central  program.

Thanks

A. Mathew

  • Hi,

    You get the RSSI value in the advertising report. So if you are using the scan module, you can keep the UUID filter (and/or other filters), but set the connect_if_match flag in the struct you pass to nrf_ble_scan_init() to false. Then the scan module will not automatically connect, but the event function you registered in the call to nrf_ble_scan_init() will be called for every received advertising packet that matches the filter.

    In the event handler, handle the NRF_BLE_SCAN_EVT_FILTER_MATCH event, read the RSSI as shown in this post. Based on that you can decide if you want to initiate a connection or not, and if you do, connect by by calling sd_ble_gap_connect() with the address of this advertiser.

  • Thank you so much Einar, 

       I have made the   init_scan.connect_if_match = false;  in the scan_init() function   then 

     inside nrf_ble_scan_on_adv_report () function   under filter match check i am getting the rssi values

    else if ((!all_filter_mode) && is_filter_matched)
    {
    scan_evt.scan_evt_id = NRF_BLE_SCAN_EVT_FILTER_MATCH;
    read_rssi = scan_evt.params.filter_match.p_adv_report->rssi;
    NRF_LOG_INFO("RSSI_value=%d",read_rssi);
    nrf_ble_scan_connect_with_target(p_scan_ctx, p_adv_report);
    }

    it worked!.

    but this rssi value is not stable  how can i verify the rssi value correclty   any idea will be a great help  because i  need to calculate the distance from rssi  and if  more then one device uuid is matched how its possible  to differentiate the previously matched and new one 

    Advance thanks.

  • Hi,

    I am glad to hear it worked.

    The RSSI will vary depending on a lot of factors, including reflections, orientation, someone walking by, on the frequency (channel), etc. Also, if the peer device is not something you have control over, then the Tx power there can also vary a lot.

    In sum, this means that you can use the RSSI number to say something like this: High RSSI means that the device is probably fairly close. A low RSSI means that the device is probably further away. If the RSSI is something in between, then perhaps the device is close but for some reason the signal is attenuated. Or perhaps it is the opposite, and due to perfect conditions (perhaps constructive interference at that location in space and that advertising channel), the signal is fairly strong even though the device is further away.

  • Hi Einar, thank you so much  i will check with HIGH RSSI. one last doubt if the UUID matched device doesn't match with my RSSI requirement so i didn't make the connection but after that the device will scan for other device  or it will  be scanning the same device.

    Advance thanks. 

Related