<?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>bt_nus_send() api returning negative value</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/102455/bt_nus_send-api-returning-negative-value</link><description>Hi Devzone, 
 I am using Nordic UART Service example and implemented my application but bt_nus_send() api will return -ve(unsucceful) value most of the time. 
 here is the code snippet regarding that 
 I have a 1030 bytes of data to be sent over Bluetooth</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 07 Aug 2023 10:59:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/102455/bt_nus_send-api-returning-negative-value" /><item><title>RE: bt_nus_send() api returning negative value</title><link>https://devzone.nordicsemi.com/thread/440086?ContentTypeID=1</link><pubDate>Mon, 07 Aug 2023 10:59:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9edfaeb1-1f13-419b-a76c-8d48d29e789a</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;br /&gt;Have you looked at my suggestion in the last reply ?&amp;nbsp;&lt;br /&gt;Please check which value returned. You receive &amp;quot;-ve&amp;quot; because you print &amp;quot;-ve&amp;quot; out.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;send_through_uart(&amp;quot;failed to send (returned -ve value)\r\n&amp;quot;);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;You need to print the actual error code out.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: bt_nus_send() api returning negative value</title><link>https://devzone.nordicsemi.com/thread/440028?ContentTypeID=1</link><pubDate>Mon, 07 Aug 2023 04:54:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:45c1ad06-5f4d-4e12-b60a-fbc7078bf9bd</guid><dc:creator>Theja</dc:creator><description>&lt;p&gt;Hi Hung Bui,&lt;/p&gt;
&lt;p&gt;I have tried to send data after sending first 20 bytes successfully but in the first 20 bytes only&amp;nbsp; it&amp;#39;s returning -ve value.&lt;/p&gt;
&lt;p&gt;is there any suggestions?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: bt_nus_send() api returning negative value</title><link>https://devzone.nordicsemi.com/thread/439708?ContentTypeID=1</link><pubDate>Thu, 03 Aug 2023 12:49:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bbb8049e-3dda-4545-b933-1dd5cbc61472</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;You can send as much as you want until you receive&amp;nbsp;NRF_ERROR_RESOURCES. Then you can wait for&amp;nbsp;BLE_GATTS_EVT_HVN_TX_COMPLETE event then you can continue.&amp;nbsp;&lt;br /&gt;Please look at the&amp;nbsp;sd_ble_gatts_hvx() description:&amp;nbsp;&lt;br /&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1691066973976v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: bt_nus_send() api returning negative value</title><link>https://devzone.nordicsemi.com/thread/439608?ContentTypeID=1</link><pubDate>Thu, 03 Aug 2023 07:09:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2e2effb6-6d4f-4ef5-8aa8-0ede2f6414a8</guid><dc:creator>Theja</dc:creator><description>&lt;p&gt;But I&amp;#39;m sending 20bytes at a time, In &amp;quot;bt_nus_send(current_conn, data_to_be_transmitted, 20)&amp;quot; this API if i change&amp;nbsp;&amp;quot;&lt;span&gt;current_conn&amp;quot; to &amp;quot;NULL&amp;quot; that means all connected peers it&amp;#39;s returning -128.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;what I&amp;#39;m thinking is that, Is there any way like callback to monitor transmission is completed or not&amp;nbsp; so&amp;nbsp;that i can send next 20 bytes after&amp;nbsp;transmission completed only.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;here is the print regarding&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;
03-08-2023 12:23:50.176 [RX] - sensing_temperature&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:24:44.519 [RX] - sensing completed and stored in flash&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:25:11.126 [RX] - advertising for packet sending&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:25:12.638 [RX] - CONNECTED&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;
failed=-128&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:25:13.698 [RX] - ACK not received&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:25:50.191 [RX] - sensing_temperature&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:26:44.418 [RX] - sensing completed and stored in flash&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:27:08.119 [RX] - advertising for packet sending&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:27:09.631 [RX] - CONNECTED&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;
failed=-128&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:27:10.693 [RX] - ACK not received&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:27:50.191 [RX] - sensing_temperature&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:28:44.445 [RX] - sensing completed and stored in flash&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:29:05.139 [RX] - advertising for packet sending&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:29:06.652 [RX] - CONNECTED&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;
failed=-128&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:29:07.712 [RX] - ACK not received&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:29:50.112 [RX] - sensing_temperature&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:30:44.349 [RX] - sensing completed and stored in flash&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:31:11.159 [RX] - advertising for packet sending&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:31:12.672 [RX] - CONNECTED&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;
ACK Received&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:31:50.142 [RX] - sensing_temperature&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:32:44.458 [RX] - sensing completed and stored in flash&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:33:08.158 [RX] - advertising for packet sending&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:33:09.670 [RX] - CONNECTED&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;
ACK Received&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:33:50.150 [RX] - sensing_temperature&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:34:44.353 [RX] - sensing completed and stored in flash&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:35:05.151 [RX] - advertising for packet sending&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:35:06.664 [RX] - CONNECTED&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;
ACK Received&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:35:50.145 [RX] - sensing_temperature&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:36:44.346 [RX] - sensing completed and stored in flash&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:37:11.057 [RX] - advertising for packet sending&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:37:12.569 [RX] - CONNECTED&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;
ACK Received&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;

03-08-2023 12:37:50.138 [RX] - sensing_temperature&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;
&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: bt_nus_send() api returning negative value</title><link>https://devzone.nordicsemi.com/thread/439510?ContentTypeID=1</link><pubDate>Wed, 02 Aug 2023 13:01:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0d983923-833e-490a-9c95-8498904db738</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;If you have a look here:&amp;nbsp;&lt;br /&gt;you can find that error 122 is&lt;br /&gt;&amp;nbsp;#define EMSGSIZE 122&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /**&amp;lt; Message size */&lt;/p&gt;
&lt;p&gt;Most likely the payload you try to send is too large.&amp;nbsp;&lt;br /&gt;Please step inside&amp;nbsp;bt_nus_send() and see what exactly throw the error.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Try to compare your code with what in the example to see why it didn&amp;#39;t work.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: bt_nus_send() api returning negative value</title><link>https://devzone.nordicsemi.com/thread/439508?ContentTypeID=1</link><pubDate>Wed, 02 Aug 2023 12:57:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f02e26e0-478c-4e11-a6e8-96236aa9933b</guid><dc:creator>Theja</dc:creator><description>&lt;p&gt;Hi Hung Bui,&lt;/p&gt;
&lt;p&gt;Thanks replying, I did that one also but I&amp;#39;m getting return value -122(unsuccessful) instead of 0(successful) from &amp;quot;bt_nus_send()&amp;quot; API.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: bt_nus_send() api returning negative value</title><link>https://devzone.nordicsemi.com/thread/439505?ContentTypeID=1</link><pubDate>Wed, 02 Aug 2023 12:50:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3137589c-3e41-4c83-9f11-46c3619d1606</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Kumar,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Please printout the actual error value.&amp;nbsp;Instead of printing this :&amp;nbsp;&lt;br /&gt;&lt;span&gt; send_through_uart(&amp;quot;failed to send (returned -ve value)\r\n&amp;quot;);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;You can print it out using:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt; send_through_uart(&amp;quot;failed to send (returned : %d)\r\n&amp;quot;,err_code);&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>