<?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 that characteristic has been subscribed to?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/5858/how-do-i-know-that-characteristic-has-been-subscribed-to</link><description>I&amp;#39;ve tried getting a notification of subscription from a bluetooth event handler like so: 
 
 
 ble_evt_dispatch() is being called from main: 
 static void ble_evt_dispatch(ble_evt_t * p_ble_evt)
 {
 on_ble_evt(p_ble_evt);
 ble_conn_params_on_ble_evt</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 01 Dec 2016 14:06:13 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/5858/how-do-i-know-that-characteristic-has-been-subscribed-to" /><item><title>RE: How do I know that characteristic has been subscribed to?</title><link>https://devzone.nordicsemi.com/thread/20443?ContentTypeID=1</link><pubDate>Thu, 01 Dec 2016 14:06:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:968a518f-474b-4640-9831-963edaf691a0</guid><dc:creator>Garret</dc:creator><description>&lt;p&gt;Why won&amp;#39;t SES ide follow the event definitions back to their base. If I right click on  BLE_GATTS_EVT_WRITE and select go to definition  I get to  BLE_GATTS_EVT_WRITE = BLE_GATTS_EVT_BASE, from this point I put the cursor over the  BLE_GATTS_EVT_BASE and do the same right click, go to definition, but the ide won&amp;#39;t take me to the definition of  BLE_GATTS_EVT_BASE, Why?? Even more confusing is that I can search the entire project/solution and  BLE_GATTS_EVT_BASE doesn&amp;#39;t show up!! Even though the ble_gap.h and ble_gatt.h files show up as Dependencies in the project tree.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I know that characteristic has been subscribed to?</title><link>https://devzone.nordicsemi.com/thread/20442?ContentTypeID=1</link><pubDate>Wed, 04 Mar 2015 11:31:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:18432223-5102-4af8-a57c-b2190f1a1cf8</guid><dc:creator>Vebj&amp;#248;rn</dc:creator><description>&lt;p&gt;I agree that it is a bit difficult to find out which event an ID corresponds to, but you can find out like this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Open ble_ranges.h and scroll down to #define BLE_EVT_BASE&lt;/li&gt;
&lt;li&gt;Look at your event id (0x0050) and find out which range this lies in. Scrolling a bit down in ble_ranges.h we see that BLE_GATTS_EVT_BASE starts at 0x50 and stops at 0x6F, so the id is a GATTS event.&lt;/li&gt;
&lt;li&gt;Open ble_gatts.h and find out where BLE_GATTS_EVT_BASE is used&lt;/li&gt;
&lt;li&gt;We see that BLE_GATTS_EVT_WRITE is defined as BLE_GATTS_EVT_BASE (0x50) and the succeeding events are increments of this. (if your code was 0x53 you would have to count down along the enum declarations, and would arrive at BLE_GATTS_EVT_HVC).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So, what you are looking for in your switch-case is BLE_GATTS_EVT_WRITE. What happens when a device subscribes to a characteristic, it writes 1 to the characteristic CCCD handle. There are examples of catching this in most of the projects in the SDK. If you look in ble_app_hrs for example, you can see the following in the &lt;em&gt;ble_hrs_on_ble_evt&lt;/em&gt; function:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; case BLE_GATTS_EVT_WRITE:
        on_write(p_hrs, p_ble_evt);
        break;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then the on_write function checks if it is a write to the cccd handle:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; static void on_write(ble_hrs_t * p_hrs, ble_evt_t * p_ble_evt){

      ble_gatts_evt_write_t * p_evt_write = &amp;amp;p_ble_evt-&amp;gt;evt.gatts_evt.params.write;

      if (p_evt_write-&amp;gt;handle == p_hrs-&amp;gt;hrm_handles.cccd_handle){
         on_hrm_cccd_write(p_hrs, p_evt_write);
      }
 }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and lastly the on_hrm_cccd_write function checks if notification has been enabled or disabled, and you can handle this acccordingly, in that function&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>