<?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>S130 HVX error codes</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/43692/s130-hvx-error-codes</link><description>Hi, 
 I am using S130 on an nRF51822 with SDK v12.3. I want to handle the different error codes that could result from calling sd_ble_gatts_hvx and retry later. 
 Firstly, there&amp;#39;s a couple of error codes that I&amp;#39;m not understanding. ble_gatts.h describes</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 19 Feb 2019 01:14:36 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/43692/s130-hvx-error-codes" /><item><title>RE: S130 HVX error codes</title><link>https://devzone.nordicsemi.com/thread/171761?ContentTypeID=1</link><pubDate>Tue, 19 Feb 2019 01:14:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fffd3665-21fe-4a44-a9c9-d5ab0cd5dcab</guid><dc:creator>tlongeri</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote userid="77062" url="~/f/nordic-q-a/43692/s130-hvx-error-codes/171648"]&amp;nbsp;Yes, this is correct but depends on each&amp;nbsp;individual&amp;nbsp;call. Searching for NRF_ERROR_INVALID_STATE or BLE_ERROR_INVALID_CONN_HANDLE in ble_gatts.h yields several results. Each return value is found described in the function brief which might help to indicate what state returned the error:[/quote]
&lt;p&gt;I was asking specifically about sd_ble_gatts_hvx.&lt;/p&gt;
[quote userid="77062" url="~/f/nordic-q-a/43692/s130-hvx-error-codes/171648"]&amp;nbsp;I would suggest reading through the API documentation of S130 header files, they include a very good description of each API call with a description of&amp;nbsp;NRF_ERROR_INVALID_STATE and&amp;nbsp;BLE_ERROR_INVALID_CONN_HANDLE.[/quote]
&lt;p&gt;This is what I initially did and what I quoted in my original question, because I found it to not be thorough enough that I would know what to expect without doing tests.&lt;/p&gt;
&lt;p&gt;Maybe &lt;em&gt;&lt;/em&gt;I am asking for too many details. Regardless of that, thank you for the answers, there were some helpful links. I have got something working (timer-less) and it has yet to fail.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Tom&amp;aacute;s&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: S130 HVX error codes</title><link>https://devzone.nordicsemi.com/thread/171648?ContentTypeID=1</link><pubDate>Mon, 18 Feb 2019 13:41:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6c3095c3-05bb-4461-aeb5-8124d643c486</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user="tal"]The third thread you linked is about what I expected, just wait for the TX_COMPLETE event and send again. I was wondering if there were any circumstances where I wouldn&amp;#39;t get the TX_COMPLETE event after getting BLE_ERROR_NO_TX_PACKETS, leaving me waiting forever. I would expect if I disconnected or if notifications were disabled, which is something I can handle, but I was worried if there were other cases.[/quote]
&lt;p&gt;&amp;nbsp;Usually, you should receive TX_COMPLETE after a BLE_ERROR_NO_TX_PACKETS, but sometimes you may miss/not receive TX_COMPLETE due to other&amp;nbsp;circumstances. If so, you&amp;#39;ll get an e.g. DISCONNECTED&amp;nbsp;event.&amp;nbsp;&lt;/p&gt;
[quote user="tal"]Regarding INVALID_STATE and INVALID_CONN_HANDLE, I still find &amp;#39;not being in a valid state&amp;#39; a bit vague. Granted, the the other possibilities for INVALID_STATE, notifications disabled and ongoing MTU exchange (the latter I only found out thanks to the thread you linked, by the way) are not vague. I guess I am probably right in thinking that after disconnecting there may be a window of time where INVALID_STATE will be returned, after which INVALID_CONN_HANDLE would be returned.[/quote]
&lt;p&gt;&amp;nbsp;Yes, this is correct but depends on each&amp;nbsp;individual&amp;nbsp;call. Searching for NRF_ERROR_INVALID_STATE or BLE_ERROR_INVALID_CONN_HANDLE in ble_gatts.h yields several results. Each return value is found described in the function brief which might help to indicate what state returned the error:&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;line 507&amp;#160;/**@brief Notify or Indicate an attribute value.

@note The local attribute value may be updated even if an outgoing packet is not sent to the peer due to an error during execution.
* When receiveing the error codes @ref NRF_ERROR_INVALID_STATE, @ref NRF_ERROR_BUSY, @ref BLE_ERROR_GATTS_SYS_ATTR_MISSING and
* @ref BLE_ERROR_NO_TX_PACKETS the Attribute Table has been updated.
* The caller can check whether the value has been updated by looking at the contents of *(p_hvx_params-&amp;gt;p_len).

@note It is important to note that a notification will &amp;lt;b&amp;gt;consume an application buffer&amp;lt;/b&amp;gt;, and will therefore
* generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted. An indication on the other hand will use the
* standard server internal buffer and thus will only generate a @ref BLE_GATTS_EVT_HVC event as soon as the confirmation
* has been received from the peer. Please see the documentation of @ref sd_ble_tx_packet_count_get for more details.&lt;/pre&gt;&lt;/p&gt;
[quote user="tal"]One of the relevant questions is &amp;#39;do I have to retry sending after receiving an INVALID_STATE? If so, can I do it in response to any event instead of using a timer?&amp;#39;. Notifications being disabled, for my particular application, would mean &amp;#39;stop sending and forget about any pending messages&amp;#39;, as would a disconnection. Since I don&amp;#39;t know exactly what INVALID_STATE means, or if I should wait for some particular event(s) after getting it, I have to be conservative with my assumptions and retry on a timer until I succeed or get a disconnection or disabled notifications event.[/quote]
&lt;p&gt;&amp;nbsp;I would suggest reading through the API documentation of S130 header files, they include a very good description of each API call with a description of&amp;nbsp;NRF_ERROR_INVALID_STATE and&amp;nbsp;BLE_ERROR_INVALID_CONN_HANDLE.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Oeyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: S130 HVX error codes</title><link>https://devzone.nordicsemi.com/thread/171468?ContentTypeID=1</link><pubDate>Fri, 15 Feb 2019 17:08:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:146a578f-fbcb-4c41-8606-18be753f8802</guid><dc:creator>tlongeri</dc:creator><description>&lt;p&gt;Thank you, your second linked thread is very clear in saying that NRF_ERROR_BUSY is returned in the specific case of sending multiple &lt;em&gt;indications&lt;/em&gt; through sd_ble_gatts_hvx without waiting for an acknowledge. Although it does not state this is the&amp;nbsp;&lt;em&gt;only&lt;/em&gt; situation that would result in this error code, I am going to go ahead and assume that is the case (I have some code that sends notifications which I modified to assert on NRF_ERROR_BUSY and I haven&amp;#39;t had trouble yet).&lt;/p&gt;
&lt;p&gt;The third thread you linked is about what I expected, just wait for the TX_COMPLETE event and send again. I was wondering if there were any circumstances where I wouldn&amp;#39;t get the TX_COMPLETE event after getting BLE_ERROR_NO_TX_PACKETS, leaving me waiting forever. I would expect if I disconnected or if notifications were disabled, which is something I can handle, but I was worried if there were other cases.&lt;/p&gt;
&lt;p&gt;Regarding INVALID_STATE and INVALID_CONN_HANDLE, I still find &amp;#39;not being in a valid state&amp;#39; a bit vague. Granted, the the other possibilities for INVALID_STATE, notifications disabled and ongoing MTU exchange (the latter I only found out thanks to the thread you linked, by the way) are not vague. I guess I am probably right in thinking that after disconnecting there may be a window of time where INVALID_STATE will be returned, after which INVALID_CONN_HANDLE would be returned.&lt;/p&gt;
&lt;p&gt;Although this is not terribly critical for my application, except for possibly the case of waiting forever for TX_COMPLETE, it would help make my code cleaner (with an added bonus of ever so slightly less power consumption by not requiring the RTC for a retry timer).&lt;/p&gt;
&lt;p&gt;One of the relevant questions is &amp;#39;do I have to retry sending after receiving an INVALID_STATE? If so, can I do it in response to any event instead of using a timer?&amp;#39;. Notifications being disabled, for my particular application, would mean &amp;#39;stop sending and forget about any pending messages&amp;#39;, as would a disconnection. Since I don&amp;#39;t know exactly what INVALID_STATE means, or if I should wait for some particular event(s) after getting it, I have to be conservative with my assumptions and retry on a timer until I succeed or get a disconnection or disabled notifications event.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: S130 HVX error codes</title><link>https://devzone.nordicsemi.com/thread/171310?ContentTypeID=1</link><pubDate>Fri, 15 Feb 2019 09:27:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3220d3ab-6e58-4ae4-8933-bf3f4ba12b2e</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]What does &amp;#39;Invalid Connection State&amp;#39; mean in this case? Which one of these would I receive if I have disconnected? I would expect to obtain BLE_ERROR_INVALID_CONN_HANDLE if I am disconnected. I was thinking maybe I get NRF_ERROR_INVALID_STATE if I have initiated a disconnection but it hasn&amp;#39;t finished yet, and BLE_ERROR_INVALID_CONN_HANDLE if I am disconnected.[/quote]
&lt;p&gt;NRF_ERROR_INVALID_STATE may mean that in this current state, the requested operation is not allowed. The device may have been disconnected during an operation, and when finalizing this operation to are not in a valid state to finish. See this &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/17897/nrf_error_invalid_state-cases/68991#68991"&gt;thread&lt;/a&gt; for more information.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;BLE_ERROR_INVALID_CONN_HANDLE is&amp;nbsp;returned&amp;nbsp;if your connection handle is not valid anymore.&lt;br /&gt;Say that you are in the middle a function and about to send data, then an interrupt fires and disconnects the device. When continuing in the function&amp;nbsp;the device will&amp;nbsp;try&amp;nbsp;to send data, in a disconnected state, you can get this error message. Some functions can also return _INVALID_STATE if called during such a race-condition.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
[quote user=""]I found &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/11493/understanding-nrf_error_busy"&gt;this S120 question&lt;/a&gt; which states that BLE layers are allowed to only queue one TX packet per connection, so NRF_ERROR_BUSY signals that another packet can&amp;#39;t be queued. I don&amp;#39;t know whether this applies to S130, and furthermore I don&amp;#39;t see when BLE_ERROR_NO_TX_PACKETS would be returned if this is the case. My question is: under what situations would each of these error codes be returned?[/quote][quote user=""]Edit: I found &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s130.api.v2.0.0%2Fgroup___b_l_e___c_o_m_m_o_n___a_p_p___b_u_f_f___m_s_c.html"&gt;this diagram&lt;/a&gt; for S130 that shows a different behavior that what is described in the S120 question I linked. Still that leaves me with the question of under what circumstances is NRF_ERROR_BUSY returned.[/quote]
&lt;p&gt;Yes, the diagram for S130 is correct and shows that different SoftDevices handle this differently.&amp;nbsp;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;NRF_ERROR_BUSY&lt;/code&gt;&lt;span&gt;&amp;nbsp;is sometimes a symptom on a function that is not used as intended, see this &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/20186/is-there-a-way-to-check-for-nrf_error_busy/78652#78652"&gt;thread&lt;/a&gt;.&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
[quote user=""]Lastly, when I get these I would prefer to retry in response to a TX_COMPLETE event instead of a timer: I think this is possible, so that if I get NRF_ERROR_BUSY or BLE_ERROR_NO_TX_PACKETS I can expect a TX_COMPLETE event 100% of the time (except possibly when I disconnect or notifications are disabled instead), is that correct?[/quote]
&lt;p&gt;This &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/24711/throughput-manage-ble_error_no_tx_packets/97260#97260"&gt;thread&lt;/a&gt; discusses somewhat how to handle the BLE_ERROR_NO_TX_PACKETS.&lt;/p&gt;
&lt;p&gt;Note that this behavior may differ slightly if you use another softdevice. Here&amp;#39;s the message sequence chart for S132 v6-series:&amp;nbsp;&lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v6.1.0/group___b_l_e___g_a_t_t_s___h_v_n___m_s_c.html"&gt;GATTS Handle Value Notification&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>