<?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>I&amp;#39;d like to know how to check the Bluetooth pairing connection in loop().</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/65932/i-d-like-to-know-how-to-check-the-bluetooth-pairing-connection-in-loop</link><description>Hello 
 I use the SDK v17 and the example ble_app_uart and use various functions such as LED, timer, buzzer, etc. I want these functions to work after Bluetooth is connected. 
 To do this, I need to be able to see when Bluetooth is connected and when</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 15 Sep 2020 08:40:59 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/65932/i-d-like-to-know-how-to-check-the-bluetooth-pairing-connection-in-loop" /><item><title>RE: I'd like to know how to check the Bluetooth pairing connection in loop().</title><link>https://devzone.nordicsemi.com/thread/269571?ContentTypeID=1</link><pubDate>Tue, 15 Sep 2020 08:40:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5f36bae5-1e83-4d67-972c-147a2601634d</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user=""]To do this, I need to be able to see when Bluetooth is connected and when it is disconnected.[/quote]
&lt;p&gt;[quote user=""][/quote]&lt;/p&gt;
&lt;p&gt;If I look at the ble_evt_handler code in the example ble_uart, there is a code for when Bluetooth is connected and when it is disconnected.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;How can I use this?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I assume you are referring to the &lt;em&gt;m_conn_handle&amp;nbsp;&lt;/em&gt;variable here?&lt;br /&gt;The simplest way to use this variable would be to create conditional checks in your program that checks whether the connection handle is INVALID or not. You may then proceed with using the peripherals.&lt;br /&gt;However, what I would recommend you do is to create a function to start and stop all your peripherals, and call it from the CONNECTED event.&lt;br /&gt;So, for example, you would like a button and LED to be functional only when connected. Then you may create a &lt;em&gt;button_and_led_start&amp;nbsp;&lt;/em&gt;function, which you call from the CONNECTED event.&lt;br /&gt;Then you will also need to create and call a&amp;nbsp;&lt;em&gt;button_and_let_stop&lt;/em&gt; function, to be called in the DISCONNECTED event.&lt;br /&gt;&lt;br /&gt;This way, your peripherals may be in a low-power or completely OFF when the device is not in a connection, which will drastically reduce average power consumption if your device is not always in a connection.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>