<?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>peripheral and central NCS `bt_conn`</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/87221/peripheral-and-central-ncs-bt_conn</link><description>HI, 
 I am developing a device that acts as both a peripheral and central device. This is working ok together, but I have one thing I cannot figure out. I separated central and peripheral parts into separate files. Both have their own callbacks (for connecting</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 03 May 2022 07:02:13 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/87221/peripheral-and-central-ncs-bt_conn" /><item><title>RE: peripheral and central NCS `bt_conn`</title><link>https://devzone.nordicsemi.com/thread/365883?ContentTypeID=1</link><pubDate>Tue, 03 May 2022 07:02:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aca6263f-7cc0-4888-8fe2-979aebc1f932</guid><dc:creator>Vojislav</dc:creator><description>&lt;p&gt;Thanks for the idea! This is what I needed.&lt;/p&gt;
&lt;p&gt;Best,&lt;br /&gt;Vojislav&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: peripheral and central NCS `bt_conn`</title><link>https://devzone.nordicsemi.com/thread/364381?ContentTypeID=1</link><pubDate>Fri, 22 Apr 2022 07:50:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ba5e59df-98bb-4853-8222-c300c1b70587</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello Vojislav,&lt;/p&gt;
&lt;p&gt;You can use the function bt_conn_get_info() from your connected callback to check the role of the connected device.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So in your connection event callback, you probably already have something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void connected(struct bt_conn *conn, uint8_t err)
{
	char addr[BT_ADDR_LE_STR_LEN];

	if (err) {
		LOG_ERR(&amp;quot;Connection failed (err %u)&amp;quot;, err);
		return;
	}

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
	LOG_INF(&amp;quot;Connected %s&amp;quot;, log_strdup(addr));

	current_conn = bt_conn_ref(conn);

	dk_set_led_on(CON_STATUS_LED);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Try adding this towards the end (at least after current_conn = bt_conn_ref(conn);)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;struct bt_conn_info my_conn_info;
int ret_val;

ret_val = bt_conn_get_info(current_conn, &amp;amp;my_conn_info);
if (ret_val) {
    LOG_INF(&amp;quot;bt_conn_geT_info failed with %d&amp;quot;, ret_val);
}
if (my_conn_info.role == BT_CONN_ROLE_CENTRAL){
    LOG_INF(&amp;quot;I am central in this connection&amp;quot;);
}
else if (my_conn_info.role == BT_CONN_ROLE_PERIPHERAL){
    LOG_INF(&amp;quot;I am peripheral in this connection&amp;quot;);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Of course, you probably want to do something other than just printing whether you are the central or the peripheral, but you get the idea &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>