<?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>strange error code 13313 (0x3401) returned by sd_ble_gatts_hvx()</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/1948/strange-error-code-13313-0x3401-returned-by-sd_ble_gatts_hvx</link><description>Hi,
I&amp;#39;m trying to update attribute value and notify it to client using sd_ble_gatts_hvx() function: 
 memset(ms, 0, sizeof(params));
 params.type=BLE_GATT_HVX_NOTIFICATION;
 params.handle=p_lbs-&amp;gt;button_char_handles.value_handle;
 params.p_data=&amp;amp;button_state;</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 07 Jun 2016 02:10:13 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/1948/strange-error-code-13313-0x3401-returned-by-sd_ble_gatts_hvx" /><item><title>RE: strange error code 13313 (0x3401) returned by sd_ble_gatts_hvx()</title><link>https://devzone.nordicsemi.com/thread/8376?ContentTypeID=1</link><pubDate>Tue, 07 Jun 2016 02:10:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:53c1b274-b1c6-4a4e-be79-ad68f6735398</guid><dc:creator>sam</dc:creator><description>&lt;p&gt;Hi Martin,&lt;/p&gt;
&lt;p&gt;i have the same problem with yours, my sd_ble_gatts_hvx always return 0x08 because I can&amp;#39;t find a way t enable the notify, i tried using sd_ble_gatts_sys_attr_set when device is re-connected but not works, please let me know if you have solved the problem, thanks..&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: strange error code 13313 (0x3401) returned by sd_ble_gatts_hvx()</title><link>https://devzone.nordicsemi.com/thread/8375?ContentTypeID=1</link><pubDate>Fri, 18 Apr 2014 10:39:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b15cb9e6-c504-4f55-a434-cb4f6979b0dd</guid><dc:creator>Martin</dc:creator><description>&lt;p&gt;I tested that for attributes with notify I have to use sd_ble_gatts_hvx() and for attributes without notify I use sd_ble_gatts_value_set(). So I made custom function with branching according what type of attribute to update and it seems to work well...&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint32_t ble_app_usr_attr_update(USR_ATTR_T *p_usr_attr)
{
  uint32_t err_code;
  ble_gatts_hvx_params_t params;
  uint16_t len=p_usr_attr-&amp;gt;length;
  
  memset(&amp;amp;params, 0, sizeof(params));
  if ((p_usr_attr-&amp;gt;props.notify!=0) || (p_usr_attr-&amp;gt;props.indicate!=0))
    { 
    if (p_usr_attr-&amp;gt;props.notify!=0)
      params.type=BLE_GATT_HVX_NOTIFICATION;
    if (p_usr_attr-&amp;gt;props.indicate!=0) 
      params.type=BLE_GATT_HVX_INDICATION;
    params.handle=p_usr_attr-&amp;gt;app_char_handles.value_handle;
    params.p_data=p_usr_attr-&amp;gt;data;
    params.p_len=&amp;amp;len;
    err_code=sd_ble_gatts_hvx(ble_conn_handle, &amp;amp;params);
    }
  else 
    err_code=sd_ble_gatts_value_set(p_usr_attr-&amp;gt;app_char_handles.value_handle, 0, &amp;amp;len, p_usr_attr-&amp;gt;data);
  DPRINTF(&amp;quot;BLE usr.attr update of service %u: len=%u, conn_h=%u, val_h=%u, err=%04Xh\n&amp;quot;, p_usr_attr-&amp;gt;service_index, *params.p_len, ble_conn_handle, p_usr_attr-&amp;gt;app_char_handles.value_handle, err_code);
  return(err_code); 
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I still get error 8 if notify is not enabled on the client side but the attribue value is updated successfully so I ignore this error in this case. When client enable notify it returns 0 (success). Attributes without notify on server side updated by sd_ble_gatts_value_set() returns 0 (success) and updated value can be readed by client as expected. As this works I keep this code and going forward...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: strange error code 13313 (0x3401) returned by sd_ble_gatts_hvx()</title><link>https://devzone.nordicsemi.com/thread/8374?ContentTypeID=1</link><pubDate>Mon, 07 Apr 2014 22:03:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:29119d53-ebc7-447c-ae9a-29fd4fa8c573</guid><dc:creator>Charles Horkin</dc:creator><description>&lt;p&gt;Having same issue...let me know if you resolve it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: strange error code 13313 (0x3401) returned by sd_ble_gatts_hvx()</title><link>https://devzone.nordicsemi.com/thread/8373?ContentTypeID=1</link><pubDate>Mon, 07 Apr 2014 11:07:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7d65e2d2-3dd7-4011-9a71-2cf3a7b7a507</guid><dc:creator>Martin</dc:creator><description>&lt;p&gt;In comments of BLE_App_UART code I can found:
&amp;quot;This function returns NRF_ERROR_INVALID_STATE if the device is not connected to a
peer or if the notification of the RX characteristic was not enabled by the peer.
It returns NRF_ERROR_NULL if the pointer p_nus is NULL.&amp;quot;&lt;/p&gt;
&lt;p&gt;So this seems that it&amp;#39;s normal to get NRF_ERROR_INVALID_STATE when client didn&amp;#39;t enabled notification yet. OK but what should I do then? I still need to update the value that client could read it itself by read command. It is already updated by sd_ble_gatts_hvx so could I ignore error int his case?
Or should I need to use different function? What about sd_ble_gatts_value_set ?
Then I would need make a branching and test some way if notification was or wasn&amp;#39;t enabled and call 2 different function for each case.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: strange error code 13313 (0x3401) returned by sd_ble_gatts_hvx()</title><link>https://devzone.nordicsemi.com/thread/8372?ContentTypeID=1</link><pubDate>Fri, 04 Apr 2014 18:01:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:66754cd8-6f32-42ee-86cb-0abd6d5b26b6</guid><dc:creator>Martin</dc:creator><description>&lt;p&gt;After I moved sd_ble_gatts_sys_attr_set(ble_conn_handle, NULL, 0) to BLE_GAP_EVT_CONNECTED event I&amp;#39;m getting error 8 - NRF_ERROR_INVALID_STATE instead of 0x3401, otherwise the same...&lt;/p&gt;
&lt;p&gt;Body of my update attr func:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;  memset(&amp;amp;params, 0, sizeof(params));
  params.type=BLE_GATT_HVX_NOTIFICATION;
  params.handle=p_svcs-&amp;gt;app_char_handles.value_handle;
  params.p_data=p_usr_attr-&amp;gt;data;
  params.p_len=&amp;amp;len;
  err_code=sd_ble_gatts_hvx(ble_conn_handle, &amp;amp;params);
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: strange error code 13313 (0x3401) returned by sd_ble_gatts_hvx()</title><link>https://devzone.nordicsemi.com/thread/8371?ContentTypeID=1</link><pubDate>Fri, 04 Apr 2014 17:13:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:deb2af03-1909-4237-b772-c5813477e69b</guid><dc:creator>Martin</dc:creator><description>&lt;p&gt;BTW it would be very helpful to have some single document with all error codes because tracking by error numbers is hard as it&amp;#39;s defined by combinations like 0x2000+0x0100+0x0030+0x0001 and I cannot simply search for 0x2131 string...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: strange error code 13313 (0x3401) returned by sd_ble_gatts_hvx()</title><link>https://devzone.nordicsemi.com/thread/8370?ContentTypeID=1</link><pubDate>Fri, 04 Apr 2014 16:58:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:13e35b1c-2526-4a06-8715-25500578029d</guid><dc:creator>Martin</dc:creator><description>&lt;p&gt;I tried again with some more printings on event but found that
BLE_GATTS_EVT_SYS_ATTR_MISSING event didn&amp;#39;t come so sd_ble_gatts_sys_attr_set() is not called.
I only captured event BLE_GAP_EVT_CONN_PARAM_UPDATE on which I do nothing - shoul I?
I tried multiple read/write from client and write (notify) on server but BLE_GATTS_EVT_SYS_ATTR_MISSING didn&amp;#39;t come up.
When I turned notification on the client I got
BLE_GATTS_EVT_WRITE
(BLE remote client write to CCCD handle: 16)
and after this happen the error disappear (code 0) on notify the attribute.
If I disable notification on client and notify again on server I got error 8 but I can read new value if I tap read button on client.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s my debug log:
bleinit
OK
advstart
OK
BLE app event: 10h
BLE client connected, handle=2579
BLE app event: 12h
BLE connection parameters updated&lt;/p&gt;
&lt;p&gt;seta[1]=20 // this I use to set atribute value and notify (calls sd_ble_gatts_hvx)
BLE usr.attr update: len=1, conn_h=2579, svc_h=12, val_h=14, err=3401h
OK
seta[1]=30
BLE usr.attr update: len=1, conn_h=2579, svc_h=12, val_h=14, err=3401h
OK
BLE app event: 50h
BLE usr.attr update from remote client: val_h=14, len=1, 1st Byte=50h
seta[1]=40
BLE usr.attr update: len=1, conn_h=2579, svc_h=12, val_h=14, err=3401h
OK
BLE app event: 50h&lt;/p&gt;
&lt;p&gt;// I enabled notification on client
BLE remote client write to CCCD handle: 16
seta[1]=41
BLE usr.attr update: len=1, conn_h=2579, svc_h=12, val_h=14, err=0000h
OK
BLE app event: 01h
BLE packet was transmitted, packet count: 1
seta[1]=42
BLE usr.attr update: len=1, conn_h=2579, svc_h=12, val_h=14, err=0000h
OK
BLE app event: 01h
BLE packet was transmitted, packet count: 1
BLE app event: 50h
BLE remote client write to CCCD handle: 16&lt;/p&gt;
&lt;p&gt;// I disabled notification on client
seta[1]=43
BLE usr.attr update: len=1, conn_h=2579, svc_h=12, val_h=14, err=0008h
OK&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: strange error code 13313 (0x3401) returned by sd_ble_gatts_hvx()</title><link>https://devzone.nordicsemi.com/thread/8369?ContentTypeID=1</link><pubDate>Mon, 31 Mar 2014 14:22:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e5e3808-cdf6-4ef4-a37a-b970b1d3646b</guid><dc:creator>Ole Morten</dc:creator><description>&lt;p&gt;I may have overlooked this, but as I said above, you could end up seeing the 0x3401 error right after connection. However, it should go away as soon as all events are handled, and the sd_ble_gatts_sys_attr_set() function has been called. (If you absolutely need to avoid seeing this error at all, you can try calling the _set() function from the connected event.) Do you see other behavior?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: strange error code 13313 (0x3401) returned by sd_ble_gatts_hvx()</title><link>https://devzone.nordicsemi.com/thread/8367?ContentTypeID=1</link><pubDate>Mon, 24 Mar 2014 09:28:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3cae8aae-00d6-4064-8c9b-32c61ad5968e</guid><dc:creator>Ole Morten</dc:creator><description>&lt;p&gt;If you already have this case, I&amp;#39;d expect this error to be returned only for a very short time, and then disappear as soon as the application has replied to the event.&lt;/p&gt;
&lt;p&gt;If you know that you&amp;#39;ll never have any system attributes stored (i.e. you don&amp;#39;t use bonding), it should be fine to move the setting of system attributes to the connected event, if you for some reason need to avoid seeing this error at all.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: strange error code 13313 (0x3401) returned by sd_ble_gatts_hvx()</title><link>https://devzone.nordicsemi.com/thread/8368?ContentTypeID=1</link><pubDate>Fri, 21 Mar 2014 19:51:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:78554d15-9277-4359-a1dc-d28fed31acd9</guid><dc:creator>Martin</dc:creator><description>&lt;p&gt;In current project I dont need bonding, it&amp;#39;s based on ble-lbs where no bondmgr is used (no ble_bondmngr_cfg.h). CCCD setting I leaved same&lt;/p&gt;
&lt;p&gt;memset(&amp;amp;cccd_md, 0, sizeof(cccd_md))
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&amp;amp;cccd_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&amp;amp;cccd_md.write_perm);
cccd_md.vloc=BLE_GATTS_VLOC_STACK;
cccd_md.vlen=0;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: strange error code 13313 (0x3401) returned by sd_ble_gatts_hvx()</title><link>https://devzone.nordicsemi.com/thread/8366?ContentTypeID=1</link><pubDate>Fri, 21 Mar 2014 19:43:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:832c5527-1fec-4000-93a0-d145bab85958</guid><dc:creator>Martin</dc:creator><description>&lt;p&gt;I already have this case block in on_ble_evt() function except without error checking. I added APP_ERROR_CHECK(err_code); line and no error appeared.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: strange error code 13313 (0x3401) returned by sd_ble_gatts_hvx()</title><link>https://devzone.nordicsemi.com/thread/8365?ContentTypeID=1</link><pubDate>Fri, 21 Mar 2014 10:24:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5fad1a56-c8b9-454d-b486-f436b0e99657</guid><dc:creator>Ole Morten</dc:creator><description>&lt;p&gt;As the error suggests, it means that the softdevice doesn&amp;#39;t yet have a set of system attributes. :-)&lt;/p&gt;
&lt;p&gt;I&amp;#39;d recommend you to read &lt;a href="https://devzone.nordicsemi.com/documentation/nrf51/5.2.0/html/a00138.html"&gt;this document&lt;/a&gt; to better understand the concept of bonding with regard to our softdevice, since it also applies to the system attributes.&lt;/p&gt;
&lt;p&gt;As you can see, bonding data is split between encryption keys and the system attributes. System attributes includes for example values for CCCDs, and the softdevice therefore needs to get those before sending any notification. Hence, when you try to send a notification, if the peer device have not yet written to the CCCDs, the softdevice will ask the application whether it has any previous bonding data to be used, by giving a BLE_GATTS_EVT_SYS_ATTR_MISSING. If the device does use bonding, the bond manager will normally handle this event, and pass back whatever data has previously been written.&lt;/p&gt;
&lt;p&gt;However, the system attributes are requested with the same event no matter if the device use bonding or not (the softdevice doesn&amp;#39;t really know that). If a device does not use bonding, but in this case, you can just reply like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
case BLE_GATTS_EVT_SYS_ATTR_MISSING:
    err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0);
    APP_ERROR_CHECK(err_code);
    break;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;No matter which of these happens, a call to sd_ble_gatts_hvx() may get this error back if it&amp;#39;s done at the exact right time, but if the call is retried just a short time later, this error should disappear, once either the application or the bond manager have set system attributes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: strange error code 13313 (0x3401) returned by sd_ble_gatts_hvx()</title><link>https://devzone.nordicsemi.com/thread/8364?ContentTypeID=1</link><pubDate>Thu, 20 Mar 2014 17:31:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:18ca24e9-00d8-4827-b92b-fa2662703458</guid><dc:creator>Martin</dc:creator><description>&lt;p&gt;Aha, OK, BLE stack use higher error numbers. I cannot find them by search because of there are composed by addind 0x3000 + 0x400 + 1 that is BLE_ERROR_GATTS_SYS_ATTR_MISSING but still don&amp;#39;t have idea what this means. I have attribute set by button_char_add() from original BLE LBS demo.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>