<?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>RSSI without connection</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/10668/rssi-without-connection</link><description>Simple question: 
 Is possible a central to evaluate RSSI before connecting to a peripheral? 
 The idea is to make central device connect and bond to a peripheral only if a determined RSSI is achieved. 
 Cheers 
 Fávero</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 13 Oct 2019 22:22:04 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/10668/rssi-without-connection" /><item><title>RE: RSSI without connection</title><link>https://devzone.nordicsemi.com/thread/214713?ContentTypeID=1</link><pubDate>Sun, 13 Oct 2019 22:22:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2b26946e-a751-4f63-affb-d0b7041d5192</guid><dc:creator>mabensur</dc:creator><description>&lt;p&gt;Complementing Anders Strand answer, when using SDK 15, things are a little different.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You can use&amp;nbsp;examples\ble_central\&lt;strong&gt;ble_app_multilink_central&lt;/strong&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;as an starting point.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;First&amp;nbsp;you need to disable auto connect in&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;scan_init()&lt;/strong&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;function:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void scan_init(void)
{
    ret_code_t          err_code;
    nrf_ble_scan_init_t init_scan;

    memset(&amp;amp;init_scan, 0, sizeof(init_scan));

    init_scan.connect_if_match = false; // I CHANGED
    init_scan.conn_cfg_tag     = APP_BLE_CONN_CFG_TAG;

    //continues... 
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Then&amp;nbsp;on&amp;nbsp;&lt;strong&gt;scan_evt_handler(scan_evt_t&amp;nbsp;const&amp;nbsp;*&amp;nbsp;p_scan_evt)&amp;nbsp;&lt;/strong&gt;function you need to add a &amp;quot;case&amp;quot; on the &amp;quot;switch case&amp;quot; to look for&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&amp;quot;NRF_BLE_SCAN_EVT_FILTER_MATCH&amp;quot; events.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;This event will happen every time the scanner finds an device with advertising data accordingly to the filter set on&amp;nbsp;&lt;strong&gt;scan_init()&lt;/strong&gt;&amp;nbsp;. In our case, devices advertising with&amp;nbsp;&amp;nbsp;&lt;/span&gt;&amp;quot;Nordic_Blinky&amp;quot; name.&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Inside this &amp;quot;case&amp;quot; you can do the following:&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void scan_evt_handler(scan_evt_t const * p_scan_evt)
{
    ret_code_t err_code;

    switch(p_scan_evt-&amp;gt;scan_evt_id)
    {
        case NRF_BLE_SCAN_EVT_CONNECTING_ERROR:
        {
            err_code = p_scan_evt-&amp;gt;params.connecting_err.err_code;
            APP_ERROR_CHECK(err_code);
        } break;

        case NRF_BLE_SCAN_EVT_FILTER_MATCH: //CASE ADDED
        {
            int read_rssi = p_scan_evt-&amp;gt;params.filter_match.p_adv_report-&amp;gt;rssi;
            
            //PRINTS PEER ID OF THE CURRENT SCAN
            NRF_LOG_RAW_INFO(&amp;quot;PEER ID = &amp;quot;)
            for (int i = 0; i &amp;lt; BLE_GAP_ADDR_LEN; i++){
                NRF_LOG_RAW_INFO(&amp;quot;%02x&amp;quot;, p_scan_evt-&amp;gt;params.connected.p_connected-&amp;gt;peer_addr.addr[i]);
            }
            NRF_LOG_RAW_INFO(&amp;quot;\r\n&amp;quot;);
            
            //PRINTS RSSI VALUE
            NRF_LOG_RAW_INFO(&amp;quot;RSSI = %d&amp;quot;, read_rssi);
            NRF_LOG_RAW_INFO(&amp;quot;\r\n&amp;quot;);
            NRF_LOG_RAW_INFO(&amp;quot;\r\n&amp;quot;);
            
            
            //NRF_LOG_INFO(&amp;quot;RSSI = %d&amp;quot;, read_rssi);
            break;
        }

        default:
            break;
    }
}&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RSSI without connection</title><link>https://devzone.nordicsemi.com/thread/39822?ContentTypeID=1</link><pubDate>Mon, 23 May 2016 06:51:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3e9bb45b-a24e-4d8c-bdab-0c4d80fb9458</guid><dc:creator>Anders Strand</dc:creator><description>&lt;p&gt;Yes, it is in dbm.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RSSI without connection</title><link>https://devzone.nordicsemi.com/thread/39821?ContentTypeID=1</link><pubDate>Fri, 20 May 2016 16:27:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2cc4bcb1-2549-461c-a6f6-7550d0ebebc0</guid><dc:creator>MicroXP</dc:creator><description>&lt;p&gt;What are the units of p_adv_report-&amp;gt;rssi? is it in dbm?&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RSSI without connection</title><link>https://devzone.nordicsemi.com/thread/39817?ContentTypeID=1</link><pubDate>Mon, 07 Dec 2015 12:40:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:acb378f6-63b0-42eb-844f-f024a80ae83b</guid><dc:creator>Anders Strand</dc:creator><description>&lt;p&gt;Every time you get a new BLE_GAP_EVT_ADV_REPORT event&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RSSI without connection</title><link>https://devzone.nordicsemi.com/thread/39816?ContentTypeID=1</link><pubDate>Fri, 04 Dec 2015 16:22:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3ca42b29-1b7a-42f2-b9c7-6e0f0889c690</guid><dc:creator>F&amp;#225;vero</dc:creator><description>&lt;p&gt;Thanks!&lt;/p&gt;
&lt;p&gt;When does the RSSI is updated? Everytime on_ble_evt is called?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RSSI without connection</title><link>https://devzone.nordicsemi.com/thread/39815?ContentTypeID=1</link><pubDate>Fri, 04 Dec 2015 15:10:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8eeacfb5-fda6-4f11-aa92-c1e4187b6b3b</guid><dc:creator>Anders Strand</dc:creator><description>&lt;p&gt;See the scanning section of the &lt;a href="https://devzone.nordicsemi.com/tutorials/21/"&gt;BLE Central Tutorial&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In most SDK examples you will have the following function handling BLE events:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void on_ble_evt(ble_evt_t * p_ble_evt)
{
    uint32_t              err_code;
    const ble_gap_evt_t * p_gap_evt = &amp;amp;p_ble_evt-&amp;gt;evt.gap_evt;	

    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GAP_EVT_ADV_REPORT:
        {
            const ble_gap_evt_adv_report_t *p_adv_report = &amp;amp;p_gap_evt-&amp;gt;params.adv_report;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The p_adv_report contains all the received advertisement data. You will find the rssi at p_adv_report-&amp;gt;rssi.&lt;/p&gt;
&lt;p&gt;See the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s110.api.v8.0.0/structble__gap__evt__adv__report__t.html?resultof=%22%62%6c%65%5f%67%61%70%5f%65%76%74%5f%61%64%76%5f%72%65%70%6f%72%74%5f%74%22%20"&gt;documentation&lt;/a&gt; on the type ble_gap_evt_adv_report_t&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RSSI without connection</title><link>https://devzone.nordicsemi.com/thread/39820?ContentTypeID=1</link><pubDate>Fri, 04 Dec 2015 11:41:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:979961bc-e6a0-4c25-9d4d-827bdbd9678d</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Don&amp;#39;t remember seeing an example. But the structure is documented, you receive the advertising event, check the rssi, if it&amp;#39;s high enough for you, you call the connect on the peripheral. That&amp;#39;s it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RSSI without connection</title><link>https://devzone.nordicsemi.com/thread/39819?ContentTypeID=1</link><pubDate>Fri, 04 Dec 2015 11:29:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:76ff81ba-d42f-4f0c-b23a-70335cefabca</guid><dc:creator>F&amp;#225;vero</dc:creator><description>&lt;p&gt;Thank you! Could you please point an example on how to do that?&lt;/p&gt;
&lt;p&gt;Fávero&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RSSI without connection</title><link>https://devzone.nordicsemi.com/thread/39818?ContentTypeID=1</link><pubDate>Fri, 04 Dec 2015 11:23:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8acd28a0-bfb6-4669-b467-e1f16fcc7683</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Well yes - the RSSI received is in the advertising report event structure, ble_gap_evt_adv_report_t. So you can read it before you connect. You can also put the TX power in the advertising packet as well if you like so you have a good idea how close the device actually is to you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>