<?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>Central node crashes just after sending data</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/88994/central-node-crashes-just-after-sending-data</link><description>Hi, 
 I have tried to use central_uart example on SDK v1.91 using nRF52832. I modified the central_uart file to send hardcoded value rather data from uart. It seems there is something that makes it crashes all the time bt_nus_client_send passes. 
 
 </description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 24 Feb 2023 09:51:01 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/88994/central-node-crashes-just-after-sending-data" /><item><title>RE: Central node crashes just after sending data</title><link>https://devzone.nordicsemi.com/thread/411883?ContentTypeID=1</link><pubDate>Fri, 24 Feb 2023 09:51:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:28e14db8-e15a-428c-803d-f5ca08b4392c</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Oli&lt;/p&gt;
&lt;p&gt;That code should work fine, yes. Just note that the &amp;quot;Data sent&amp;quot; text would be printed regardless,&amp;nbsp;to me the following version would be more appropriate:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int err;

err = bt_nus_client_send();
if(err){
    LOG_WRN(&amp;quot;Failed to send data over BLE connection (err %d)&amp;quot;, err);
}
else {
    LOG_INF(&amp;quot;Data sent&amp;quot;);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;All error codes will be returned as negative numbers, and it is common practice to check for errors by checking if err &amp;lt; 0, but for functions that never return positive numbers it is sufficient simply to check the variable directly like in your example.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Central node crashes just after sending data</title><link>https://devzone.nordicsemi.com/thread/411776?ContentTypeID=1</link><pubDate>Thu, 23 Feb 2023 18:23:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c9662237-ae44-4a0f-80ee-b2f5fb895fb0</guid><dc:creator>Oli</dc:creator><description>&lt;p&gt;Hi &lt;a href="https://devzone.nordicsemi.com/members/ovrebekk"&gt;ovrebekk&lt;/a&gt;&amp;nbsp;,&lt;/p&gt;
&lt;p&gt;Thanks for the reply. Can I just equate the bt_nus_client_send() to a variable and make sure that it returns 0? Please see below:&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int err;

err = bt_nus_client_send();
if(err){
    LOG_WRN(&amp;quot;Failed to send data over BLE connection (err %d)&amp;quot;, err);
}
LOG_INF(&amp;quot;Data sent&amp;quot;);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;oli&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Central node crashes just after sending data</title><link>https://devzone.nordicsemi.com/thread/410072?ContentTypeID=1</link><pubDate>Wed, 15 Feb 2023 12:39:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f31a1244-9534-4aa3-bfca-d1753ab60f1e</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Oli&lt;/p&gt;
&lt;p&gt;Simon is currently unavailable, and I will handle your case in the mean time.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Removing the semaphore doesn&amp;#39;t necessarily cause a problem, but it means there is a risk that you will call the &lt;em&gt;bt_nus_client_send(..) &lt;/em&gt;function while the current transaction is still ongoing.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If this happens the &lt;em&gt;bt_nus_client_send(..)&lt;/em&gt; function will return the EALREADY error, as shown &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/main/subsys/bluetooth/services/nus_client.c#L96"&gt;here&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In other words, if you plan to remove this semaphore you should add some code in the application to check for this error. When this error occurs the data will not be sent, and you need to send it at a later time if you want to avoid data loss.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Central node crashes just after sending data</title><link>https://devzone.nordicsemi.com/thread/409230?ContentTypeID=1</link><pubDate>Thu, 09 Feb 2023 19:36:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:28d11e54-1fe2-45f5-b491-045faf958adf</guid><dc:creator>Oli</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/simoniversen"&gt;Simon&lt;/a&gt;,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I would like to ask, what if I don&amp;#39;t remove the k_sem_give() and removed the k_sem_take()? Would that cause a problem in my code?&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;oli&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Central node crashes just after sending data</title><link>https://devzone.nordicsemi.com/thread/372859?ContentTypeID=1</link><pubDate>Thu, 16 Jun 2022 14:36:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:045f2ea8-10d3-4350-a2a9-49419057c5c3</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Inside central_uart/main.c--&amp;gt;ble_data_sent(), comment out k_free(buf), so it looks like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void ble_data_sent(struct bt_nus_client *nus, uint8_t err,
					const uint8_t *const data, uint16_t len)
{
	ARG_UNUSED(nus);

	struct uart_data_t *buf;

	/* Retrieve buffer context. */
	//buf = CONTAINER_OF(data, struct uart_data_t, data);
	//k_free(buf);

	k_sem_give(&amp;amp;nus_write_sem);

	if (err) {
		LOG_WRN(&amp;quot;ATT error code: 0x%02X&amp;quot;, err);
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I did that, and then your sample worked&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>