<?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 do I know when a connection was established and how do I use the relavent struct?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/11408/how-do-i-know-when-a-connection-was-established-and-how-do-i-use-the-relavent-struct</link><description>8.0, multilink example, peripheral, s110 softdevice. 
 By walking through sections of codes and doing some research, I reckon if a connection were being established after advertising, the callback &amp;quot;ble_evt_handler()&amp;quot;
will be called upon, and a &amp;quot;p_ble_evt</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 20 Jan 2016 13:08:28 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/11408/how-do-i-know-when-a-connection-was-established-and-how-do-i-use-the-relavent-struct" /><item><title>RE: How do I know when a connection was established and how do I use the relavent struct?</title><link>https://devzone.nordicsemi.com/thread/43009?ContentTypeID=1</link><pubDate>Wed, 20 Jan 2016 13:08:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f6be724a-e828-4002-a875-61786cd97b35</guid><dc:creator>Erik</dc:creator><description>&lt;p&gt;Thank you for your answers and kind attention!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I know when a connection was established and how do I use the relavent struct?</title><link>https://devzone.nordicsemi.com/thread/43006?ContentTypeID=1</link><pubDate>Wed, 20 Jan 2016 12:29:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b89ef6a9-3fb1-4cfa-9c61-d2ba0c8fcb05</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;This approach is also used by most SDK examples.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I know when a connection was established and how do I use the relavent struct?</title><link>https://devzone.nordicsemi.com/thread/43007?ContentTypeID=1</link><pubDate>Wed, 20 Jan 2016 10:51:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bb3286d7-b394-4f78-ae8e-1df38f19ef28</guid><dc:creator>Marco Russi</dc:creator><description>&lt;p&gt;Thanks for reminding me this approach. ;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I know when a connection was established and how do I use the relavent struct?</title><link>https://devzone.nordicsemi.com/thread/43005?ContentTypeID=1</link><pubDate>Tue, 19 Jan 2016 13:08:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dd1f086e-56b6-41b4-a4c7-84bf2c7b8240</guid><dc:creator>Alex</dc:creator><description>&lt;p&gt;Another option is to use connection handle&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;case BLE_GAP_EVT_CONNECTED:
    m_conn_handle = p_ble_evt-&amp;gt;evt.gap_evt.conn_handle;

    break;

case BLE_GAP_EVT_DISCONNECTED:
    m_conn_handle = BLE_CONN_HANDLE_INVALID;
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I know when a connection was established and how do I use the relavent struct?</title><link>https://devzone.nordicsemi.com/thread/43008?ContentTypeID=1</link><pubDate>Tue, 19 Jan 2016 12:58:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1fa3de36-f83f-43a6-943b-a7eba9d10cda</guid><dc:creator>Marco Russi</dc:creator><description>&lt;p&gt;Hi,
your idea should work fine.
I did the same on a my application.
I suggest to define the flag &lt;em&gt;static volatile&lt;/em&gt; as below:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static volatile bool device_connected = false;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can find it here:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/marcorussi/nrf51_led_dimmer/blob/master/conn_nus_p.c"&gt;github.com/.../conn_nus_p.c&lt;/a&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;switch (p_ble_evt-&amp;gt;header.evt_id){

    case BLE_GAP_EVT_CONNECTED:
		/* device is connected now */
		device_connected = true;
        break;


    case BLE_GAP_EVT_DISCONNECTED:
		/* device is not connected now */
		device_connected = false;
        break;}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>