<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to get RSSI from a nRF52832 beacon using nRF52</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/57693/how-to-get-rssi-from-a-nrf52832-beacon-using-nrf52</link><description>Hello everyone, 
 I just started learning BLE. I want to develop an application that gets RSSI from a beacon and displays the magnitude of RSSI using 4 built-in LEDs. 
 Beacon | Scanner(nRF52840) 
 -100 ~ -80 dBm = no leds lit up 
 -80 ~ -60 dBm = LED1</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 14 Feb 2020 13:36:02 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/57693/how-to-get-rssi-from-a-nrf52832-beacon-using-nrf52" /><item><title>RE: How to get RSSI from a nRF52832 beacon using nRF52</title><link>https://devzone.nordicsemi.com/thread/234423?ContentTypeID=1</link><pubDate>Fri, 14 Feb 2020 13:36:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2815f68a-a511-495d-ba5d-a08c89e908d0</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="dalsee"]Q1. Now I am being confused, what should I define for the argument &amp;#39;target_uuid&amp;#39;?[/quote]
&lt;p&gt;You can refer to the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/ble_sdk_app_nus_c.html"&gt;BLE UART central example&lt;/a&gt; to see how the scan module is used to filter on the 128 bit UUID (see the scan_init() function).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get RSSI from a nRF52832 beacon using nRF52</title><link>https://devzone.nordicsemi.com/thread/234279?ContentTypeID=1</link><pubDate>Thu, 13 Feb 2020 20:24:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:00cd9b17-58dc-4111-88d9-fe3545717d1e</guid><dc:creator>dalsee</dc:creator><description>&lt;p&gt;Hello, &lt;/p&gt;
&lt;p&gt;The below code resulted the compile error,&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int read_rssi = p_scan_evt-&amp;gt;filter_match.p_adv_report-&amp;gt;rssi;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;but I think I managed to resolve the issue by adding &amp;#39;params.&amp;#39; in front of the struct and now it works :D&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int read_rssi = p_scan_evt-&amp;gt;params.filter_match.p_adv_report-&amp;gt;rssi;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks for you help. And now I want to filter the beacon&amp;#39;s UUID because I want to read the target&amp;#39;s RSSI only. Since my beacon device is using ble_app_beacon example, its UUID seems to be 128bit long. &lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Q1. Now I am being confused, what should I define for the argument &amp;#39;target_uuid&amp;#39;?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;err_code = nrf_ble_scan_filter_set(&amp;amp;m_scan, SCAN_UUID_FILTER, &amp;amp;target_uuid);
APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get RSSI from a nRF52832 beacon using nRF52</title><link>https://devzone.nordicsemi.com/thread/234221?ContentTypeID=1</link><pubDate>Thu, 13 Feb 2020 14:48:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1d81e04-c5fa-40fb-91f3-6a664d526cdd</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="dalsee"]Q1. I want both devices(beacon, scanner) stay unconnected while the scanner is getting advertisement data from the beacon. Should then I use &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v7.0.1/structble__gap__evt__adv__report__t.html"&gt;ble_gap_evt_adv_report_t&lt;/a&gt; command in scan_evt_handler, not ble_evt_handler?[/quote]
&lt;p&gt;I did not fully understand the question. If you use the scanning module, then it makes sense to do it in the&amp;nbsp;scan_evt_handler(). But it is actually the same event with the same information you get the&amp;nbsp;ble_evt_handler. This is not related to connections etc.&lt;/p&gt;
[quote user="dalsee"]Q2. How can I use the &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v7.0.1/structble__gap__evt__adv__report__t.html"&gt;ble_gap_evt_adv_report_t&lt;/a&gt; command in the handler? If I want to save RSSI value in a buffer, is it possible to use like this?[/quote]
&lt;p&gt;The&amp;nbsp;ble_gap_evt_adv_report_t struct is not a command, but a struct that is passed to the application from the SoftDevice when there is an advertising report event (BLE_GAP_EVT_ADV_REPORT). The way you try to use it is not correct, and it is not legal C code. You can refer to the example in &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/38260/how-to-get-the-scan-response-datafor-the-center/149047#149047"&gt;this post&lt;/a&gt; if you want to see how to scan without the scan module (which is simpler if you don&amp;#39;t need filtering). If you continue to use the scan module and get a hit, then you can access the rssi by replacing &amp;quot;ble_gap_evt_adv_report_t-&amp;gt;rssi;&amp;quot; with &amp;quot;p_scan_evt-&amp;gt;filter_match.p_adv_report-&amp;gt;rssi&amp;quot;.&lt;/p&gt;
[quote user="dalsee"]Q3. I am using ble_app_blinky_c example for the scanner device. If I do not want the connection, do I need the ble_evt_handler like below?[/quote]
&lt;p&gt;Since you use the scan module, you just need to make sure you set&amp;nbsp;connect_if_match to false instead of true when you initialize it (calling&amp;nbsp;nrf_ble_scan_init()).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get RSSI from a nRF52832 beacon using nRF52</title><link>https://devzone.nordicsemi.com/thread/234063?ContentTypeID=1</link><pubDate>Wed, 12 Feb 2020 17:09:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4db6a85a-b445-4ee8-86e5-08cb9858550c</guid><dc:creator>dalsee</dc:creator><description>&lt;p&gt;Hello, Einar,&lt;/p&gt;
&lt;p&gt;Thanks for your kind reply. I now have 3 questions.&lt;/p&gt;
&lt;p&gt;Q1. I want both devices(beacon, scanner) stay unconnected while the scanner is getting advertisement data from the beacon. Should then I use &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v7.0.1/structble__gap__evt__adv__report__t.html"&gt;ble_gap_evt_adv_report_t&lt;/a&gt; command in scan_evt_handler, not ble_evt_handler?&lt;/p&gt;
&lt;p&gt;Q2. How can I use the &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v7.0.1/structble__gap__evt__adv__report__t.html"&gt;ble_gap_evt_adv_report_t&lt;/a&gt; command in the handler? If I want to save RSSI value in a buffer, is it possible to use like this?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void scan_evt_handler(scan_evt_t const * p_scan_evt)
{
    ret_code_t err_code;

    static int16_t rssi_buffer[100];
    static int idx = 0;
    
    switch(p_scan_evt-&amp;gt;scan_evt_id)
    {
        case NRF_BLE_SCAN_EVT_FILTER_MATCH: 
            rssi_buffer[idx] = ble_gap_evt_adv_report_t-&amp;gt;rssi;
            idx++;
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Q3. I am using ble_app_blinky_c example for the scanner device. If I do not want the connection, do I need the ble_evt_handler like below?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    ret_code_t err_code;

    // For readability.
    ble_gap_evt_t const * p_gap_evt = &amp;amp;p_ble_evt-&amp;gt;evt.gap_evt;

    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        // Upon connection, check which peripheral has connected (HR or RSC), initiate DB
        // discovery, update LEDs status and resume scanning if necessary. */
        case BLE_GAP_EVT_CONNECTED:
        {
            NRF_LOG_INFO(&amp;quot;Connected.&amp;quot;);
            err_code = ble_lbs_c_handles_assign(&amp;amp;m_ble_lbs_c, p_gap_evt-&amp;gt;conn_handle, NULL);
            APP_ERROR_CHECK(err_code);

            err_code = ble_db_discovery_start(&amp;amp;m_db_disc, p_gap_evt-&amp;gt;conn_handle);
            APP_ERROR_CHECK(err_code);

            // Update LEDs status, and check if we should be looking for more
            // peripherals to connect to.
            bsp_board_led_on(CENTRAL_CONNECTED_LED);
            bsp_board_led_off(CENTRAL_SCANNING_LED);
        } break;

        // Upon disconnection, reset the connection handle of the peer which disconnected, update
        // the LEDs status and start scanning again.
        case BLE_GAP_EVT_DISCONNECTED:
        {
            NRF_LOG_INFO(&amp;quot;Disconnected.&amp;quot;);
            scan_start();
        } break;

        case BLE_GAP_EVT_TIMEOUT:
        {
            // We have not specified a timeout for scanning, so only connection attemps can timeout.
            if (p_gap_evt-&amp;gt;params.timeout.src == BLE_GAP_TIMEOUT_SRC_CONN)
            {
                NRF_LOG_DEBUG(&amp;quot;Connection request timed out.&amp;quot;);
            }
        } break;

        case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST:
        {
            // Accept parameters requested by peer.
            err_code = sd_ble_gap_conn_param_update(p_gap_evt-&amp;gt;conn_handle,
                                        &amp;amp;p_gap_evt-&amp;gt;params.conn_param_update_request.conn_params);
            APP_ERROR_CHECK(err_code);
        } break;

        case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
        {
            NRF_LOG_DEBUG(&amp;quot;PHY update request.&amp;quot;);
            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-&amp;gt;evt.gap_evt.conn_handle, &amp;amp;phys);
            APP_ERROR_CHECK(err_code);
        } break;

        case BLE_GATTC_EVT_TIMEOUT:
        {
            // Disconnect on GATT Client timeout event.
            NRF_LOG_DEBUG(&amp;quot;GATT Client Timeout.&amp;quot;);
            err_code = sd_ble_gap_disconnect(p_ble_evt-&amp;gt;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.
            NRF_LOG_DEBUG(&amp;quot;GATT Server Timeout.&amp;quot;);
            err_code = sd_ble_gap_disconnect(p_ble_evt-&amp;gt;evt.gatts_evt.conn_handle,
                                             BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            APP_ERROR_CHECK(err_code);
        } break;

        default:
            // No implementation needed.
            break;
    }
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you all !&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get RSSI from a nRF52832 beacon using nRF52</title><link>https://devzone.nordicsemi.com/thread/233963?ContentTypeID=1</link><pubDate>Wed, 12 Feb 2020 12:47:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:691a02b9-4fd9-4c79-b8b0-5891613399e0</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You will get an advertising report event when an advertising packet is received while scanning, and this includes the RSSI. See documentation for &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v7.0.1/structble__gap__evt__adv__report__t.html"&gt;ble_gap_evt_adv_report_t&lt;/a&gt;&amp;nbsp;for details.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>