<?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 if my CCCD handles is set and how many CCCD handles usually are there?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/23034/how-do-i-know-if-my-cccd-handles-is-set-and-how-many-cccd-handles-usually-are-there</link><description>Sorry that I&amp;#39;m asking 2 questions in one go, but they are closely related. 
 Problem: got 0x00000008, INVALID_STATE error when calling sd_ble_gatts_hvx, looked it up, it&amp;#39;s most likely CCCD not set. 
 The thing is I&amp;#39;ve been migrating from nrf51 to 52</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 01 Jul 2017 11:42:51 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/23034/how-do-i-know-if-my-cccd-handles-is-set-and-how-many-cccd-handles-usually-are-there" /><item><title>RE: How do I know if my CCCD handles is set and how many CCCD handles usually are there?</title><link>https://devzone.nordicsemi.com/thread/90614?ContentTypeID=1</link><pubDate>Sat, 01 Jul 2017 11:42:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:149728cc-3257-4248-b5d1-2ed61da082e1</guid><dc:creator>Mitch996</dc:creator><description>&lt;p&gt;Hello @endnode, this is the 3rd time I&amp;#39;m reading your answer, and I tried out the function you recommended, regrettably it didn&amp;#39;t work exactly the way I anticipated it...could you please take a look at &lt;a href="https://devzone.nordicsemi.com/question/155315/how-do-i-use-sd_ble_gatts_value_get-to-read-the-value-of-cccd-handle/"&gt;this question&lt;/a&gt;?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I know if my CCCD handles is set and how many CCCD handles usually are there?</title><link>https://devzone.nordicsemi.com/thread/90613?ContentTypeID=1</link><pubDate>Sat, 24 Jun 2017 16:01:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:213b750f-bed0-4b04-a537-486ba77e7c23</guid><dc:creator>endnode</dc:creator><description>&lt;p&gt;Hi Mitch,&lt;/p&gt;
&lt;p&gt;This mechanism hasn&amp;#39;t changed since original nRF51 Soft Devices:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;When you are provisioning GATT Server role and you have any Characteristic with Notifications or Indications enabled you will automatically get handle numbers for both Value and CCCD handles. This will happen for any such Characteristic (because every such Characteristic has its own CCCD - as explained in BT SIG spec). &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s140.api.v5.0.0/group___b_l_e___g_a_t_t_s___f_u_n_c_t_i_o_n_s.html#ga9ee07ea4b96dcca1537b01ff9a7692ba"&gt;See &lt;code&gt;p_handles&lt;/code&gt; parameter of &lt;code&gt;sd_ble_gatts_characteristic_add&lt;/code&gt; for more details&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Once you get any GAP Peripheral connection you will in your GATT Server event handler watch for Write events. Once you (from event data) see that Write targets one of CCCDs and it contains value (typically 16 bits) which enable particular Notification or Indication method you can start using it. Otherwise if you try and method is not enabled you get error as you do in your example right now.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There is even nice function for it in nRF5 SDK V13.0.0 &lt;code&gt;examples\ble_peripheral\ble_app_pwr_profiling\main.c&lt;/code&gt; example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/**@brief Function for evaluating the value written in CCCD
 *
 * @details This shall be called when there is a write event received from the stack. This
 *          function will evaluate whether or not the peer has enabled notifications and
 *          start/stop notifications accordingly.
 *
 * @param[in]   p_ble_evt   Bluetooth stack event.
 */
static void on_write(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 == m_char_handles.cccd_handle) &amp;amp;&amp;amp; (p_evt_write-&amp;gt;len == 2)) {
        // CCCD written. Start notifications
        m_is_notifying_enabled = ble_srv_is_notification_enabled(p_evt_write-&amp;gt;data);

        if (m_is_notifying_enabled) {
            // Start using HVX here...

        }
        // ...
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To your questions:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;I don&amp;#39;t think there would be any real-time (run-time) access to GATT Server emulation inside Soft Device so I don&amp;#39;t think you could read this from any offset or variable during debug of your application code. However when reading S13x/S140 GATTS API it looks like calling &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s140.api.v5.0.0/group___b_l_e___g_a_t_t_s___f_u_n_c_t_i_o_n_s.html?cp=2_3_1_0_0_2_4_2_12#gad95321e157e632e7ac3a77f3388cbdf7"&gt;sd_ble_gatts_value_get(...)&lt;/a&gt; any time you are unsure will give you desired CCCD value (you just need to say which Connection handle and (G)ATT handle you want to read, therefore you need to remember CCCD handle value from GATTS provisioning as explained above).&lt;/li&gt;
&lt;li&gt;This is answered above.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Cheers Jan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>