<?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>Get connection status in Zephyr</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/89057/get-connection-status-in-zephyr</link><description>Hi, 
 I want to monitor the connection state of my device as I have observed situations in which the callback functions defined with bt_conn_cb_register is not fired, causing the device to no longer advertise. 
 I guess i somehow should update my bt_conn</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 21 Jun 2022 22:50:04 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/89057/get-connection-status-in-zephyr" /><item><title>RE: Get connection status in Zephyr</title><link>https://devzone.nordicsemi.com/thread/373549?ContentTypeID=1</link><pubDate>Tue, 21 Jun 2022 22:50:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cd2b1715-1bd4-40bb-8036-b0606ef1c254</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Would you be able to upload a minimal reproducible sample, such that I could investigate why callback functions don&amp;#39;t get called?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Get connection status in Zephyr</title><link>https://devzone.nordicsemi.com/thread/373094?ContentTypeID=1</link><pubDate>Fri, 17 Jun 2022 16:26:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:925bc6f9-a2cd-4013-a481-150e1491642d</guid><dc:creator>Simon</dc:creator><description>[quote user=""]I guess i somehow should update my bt_conn variable from a connection handle and read the state but I haven&amp;#39;t found a way to do it.[/quote]
&lt;p&gt;I don&amp;#39;t think you need to do anyting like this. All your connections are stored inside the array &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/subsys/bluetooth/host/conn.c#L63"&gt;bt_conn acl_conns&lt;/a&gt;. When you start the connectable advertising, a new bt_conn instance is automatically added to this array using &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/subsys/bluetooth/host/adv.c#L915"&gt;bt_conn_add_le().&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Then when an event happens for a specific connction it will go through all the callbacks added (possible to have several instances of &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v2.7.99-ncs1/include/bluetooth/conn.h#L766-L767"&gt;bt_conn_cb&lt;/a&gt;). For example in the function &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/subsys/bluetooth/host/conn.c#L1294-L1298"&gt;notify_connected()&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I will ask some developers to look through my answer on Monday, to make sure the information I have given you is correct. I&amp;#39;m also interested in taking a deeper look at why the callbacks stops firing.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>