<?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>sd_ble_gatts_hvx indication sets len 0 and doesn&amp;#39;t call onCharacteristicChanged on Adroid App</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/56613/sd_ble_gatts_hvx-indication-sets-len-0-and-doesn-t-call-oncharacteristicchanged-on-adroid-app</link><description>Hi, 
 
 I trying to send indication supplied with some data to my Android app (which BTW works fine with other BLE devices) as an answer to characteristic write command 
 Here is my sequence of calls: 
 Android: 
 1) Discover services and characteristic</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 19 Jan 2020 20:16:29 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/56613/sd_ble_gatts_hvx-indication-sets-len-0-and-doesn-t-call-oncharacteristicchanged-on-adroid-app" /><item><title>RE: sd_ble_gatts_hvx indication sets len 0 and doesn't call onCharacteristicChanged on Adroid App</title><link>https://devzone.nordicsemi.com/thread/229732?ContentTypeID=1</link><pubDate>Sun, 19 Jan 2020 20:16:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4535d4d8-9b46-4e65-8934-eec8569f9529</guid><dc:creator>x_arrange</dc:creator><description>&lt;p&gt;result is the same: if len = MTU, nothing sent&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sd_ble_gatts_hvx indication sets len 0 and doesn't call onCharacteristicChanged on Adroid App</title><link>https://devzone.nordicsemi.com/thread/229727?ContentTypeID=1</link><pubDate>Sat, 18 Jan 2020 18:41:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4dd02050-b8ed-472e-b466-cc1ab989d7b7</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Sorry. Yes you are right&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sd_ble_gatts_hvx indication sets len 0 and doesn't call onCharacteristicChanged on Adroid App</title><link>https://devzone.nordicsemi.com/thread/229705?ContentTypeID=1</link><pubDate>Fri, 17 Jan 2020 19:29:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3c0c8f65-ac5f-46f9-9446-9a0ed3af0d2b</guid><dc:creator>x_arrange</dc:creator><description>&lt;p&gt;Have you ment &amp;quot;params.p_len = &amp;amp;len&amp;quot;?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sd_ble_gatts_hvx indication sets len 0 and doesn't call onCharacteristicChanged on Adroid App</title><link>https://devzone.nordicsemi.com/thread/229654?ContentTypeID=1</link><pubDate>Fri, 17 Jan 2020 14:35:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cae2fb36-bb05-4818-b096-dafe76eda577</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Looking at the implementation of HVX inside softdevice, the documentation looks correct. So I am not sure why you see that behaviour.&lt;/p&gt;
&lt;p&gt;Can you try the below instead in your write_response and see what happens?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void write_response(uint16_t conn_handle, uint16_t char_handle, uint16_t len, uint8_t *data){
    ble_gatts_hvx_params_t params;
    uint16_t wr_len =0;
    memset(&amp;amp;params, 0, sizeof(ble_gatts_hvx_params_t));
    params.handle = char_handle;
    params.type = BLE_GATT_HVX_INDICATION;
    params.p_len = len;
    params.p_data = data;
    params.offset = 0;    

    ble_gatts_value_t pvalue;
    memset(&amp;amp;pvalue, 0, sizeof(ble_gatts_value_t));
    pvalue.len = len;
    pvalue.offset = 0;
    pvalue.p_value = data;

    uint32_t err = sd_ble_gatts_value_set(conn_handle, char_handle, &amp;amp;pvalue);
    if (err != NRF_SUCCESS) printf(&amp;quot;\tsd_ble_gatts_value_set ERROR: %x\n&amp;quot;,err); // else printf(&amp;quot;\tsd_ble_gatts_value_set OK: %d\n&amp;quot;,pvalue.len);
    
    printf(&amp;quot;\twrite_response: conn_h: %d, cchar_h: %d, len=%d\n&amp;quot;, conn_handle, char_handle, len);
    err = sd_ble_gatts_hvx(conn_handle, &amp;amp;params);
    if (err != NRF_SUCCESS) printf(&amp;quot;\tsd_ble_gatts_hvx ERROR: %x\n&amp;quot;,err); else printf(&amp;quot;\tsd_ble_gatts_hvx OK: %d\n&amp;quot;,wr_len);
   
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sd_ble_gatts_hvx indication sets len 0 and doesn't call onCharacteristicChanged on Adroid App</title><link>https://devzone.nordicsemi.com/thread/229472?ContentTypeID=1</link><pubDate>Thu, 16 Jan 2020 17:07:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6bc0802b-dcdb-4c71-bcf3-0f3e0535dcd7</guid><dc:creator>x_arrange</dc:creator><description>&lt;p&gt;... and another&amp;nbsp;discovery that is not documented!&lt;/p&gt;
&lt;p&gt;apparently&amp;nbsp;ble_gatts_hvx_params_t member p_len had to be set to less or equal to current MTU-3. In this case indication&amp;nbsp;will be sent&lt;/p&gt;
&lt;p&gt;Why is that? And why documentation&amp;nbsp;doesn&amp;#39;t say a word about it?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sd_ble_gatts_hvx indication sets len 0 and doesn't call onCharacteristicChanged on Adroid App</title><link>https://devzone.nordicsemi.com/thread/229462?ContentTypeID=1</link><pubDate>Thu, 16 Jan 2020 15:59:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fd032606-2868-4901-b565-35f2c532184a</guid><dc:creator>x_arrange</dc:creator><description>&lt;p&gt;So... looks like I found a bug:&lt;/p&gt;
&lt;p&gt;Comments in ble_gatts.h says:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1579189952720v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;that means my write_response function is OK.&lt;/p&gt;
&lt;p&gt;But whe I set &amp;nbsp;params.p_data = data (existing pointer)&amp;nbsp; then I do get&amp;nbsp;onCharacteristicChanged called on Android. BUT with&amp;nbsp;zero-length byte array&lt;/p&gt;
&lt;p&gt;So I decided to&amp;nbsp;set wr_len = len hoping that in this case I&amp;#39;ll get data in Android but I didn&amp;#39;t -&amp;nbsp;&lt;span&gt;onCharacteristicChanged&amp;nbsp;again not called.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I might say -&amp;nbsp;API documentation/comments are&amp;nbsp;very unclear..&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>