<?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>my bluetooth gets disconnected while sending continous stream of data</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/12512/my-bluetooth-gets-disconnected-while-sending-continous-stream-of-data</link><description>hi,
i am using uart example from nrf51822 example. when i am sending continuous stream of data then my connection breaks. it disconnects from peripheral device.
how should i overcome from this situation.
i think i am missing some data exchange concept</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 22 Mar 2016 00:40:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/12512/my-bluetooth-gets-disconnected-while-sending-continous-stream-of-data" /><item><title>RE: my bluetooth gets disconnected while sending continous stream of data</title><link>https://devzone.nordicsemi.com/thread/47446?ContentTypeID=1</link><pubDate>Tue, 22 Mar 2016 00:40:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d27dc8be-bddd-4d29-8668-42d1e22af372</guid><dc:creator>MANGO</dc:creator><description>&lt;p&gt;Hmm, I think you just have to change the packet at &lt;code&gt;ble_nus_string_send&lt;/code&gt; at &lt;code&gt;my_nus_iter&lt;/code&gt; function.&lt;/p&gt;
&lt;p&gt;Use a global variable or change the function input to get the packet you&amp;#39;ve like to send&lt;/p&gt;
&lt;p&gt;and I think it will be  all done.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: my bluetooth gets disconnected while sending continous stream of data</title><link>https://devzone.nordicsemi.com/thread/47445?ContentTypeID=1</link><pubDate>Thu, 17 Mar 2016 20:53:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7a1d1297-d12e-40b7-92ab-a64a4bfb6cb2</guid><dc:creator>Deepak Kumar</dc:creator><description>&lt;p&gt;hi mango,
thanks for your help.
your example send data continuously.
the issue i am facing is i want to send live sensor data continuously. data keeps changing each time.
this example is capable of sending same data itrating. but in my case i am sending different data continuously without iteration.&lt;/p&gt;
&lt;p&gt;kindly guide me in that aspect.&lt;/p&gt;
&lt;p&gt;thanks!!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: my bluetooth gets disconnected while sending continous stream of data</title><link>https://devzone.nordicsemi.com/thread/47444?ContentTypeID=1</link><pubDate>Sun, 13 Mar 2016 18:28:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0068444d-ee8c-4d2a-b437-644f0d9f9f0f</guid><dc:creator>MANGO</dc:creator><description>&lt;p&gt;Thanks for waiting. I&amp;#39;m using codes from SDK 7.2 so modify the code for SDK 10.&lt;/p&gt;
&lt;p&gt;Also, your source files might be seperated from BLE handling parts.&lt;/p&gt;
&lt;p&gt;So you have to manage global variables to take care of this.&lt;/p&gt;
&lt;p&gt;You might have to change your &lt;code&gt;sendData&lt;/code&gt; function too.&lt;/p&gt;
&lt;p&gt;The concept is quite simple. I referenced this trick from the devzone a year ago. I will post the link later if I find it.&lt;/p&gt;
&lt;p&gt;After you used &lt;code&gt;ble_nus_string_send&lt;/code&gt; and successfully sends a string, &lt;code&gt;on_ble_evt&lt;/code&gt; and&lt;/p&gt;
&lt;p&gt;other dispatching functions are called for the &lt;code&gt;BLE_EVT_TX_COMPLETE&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Using this feature, you can make an iterating loop to &amp;quot;&lt;em&gt;continuously&lt;/em&gt;&amp;quot; send multiple data.&lt;/p&gt;
&lt;p&gt;I will give you an example below so modify it for your own.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// global variable
bool       m_do_nus_iteration = false;
uint16_t m_iter = 5; // number of iteration
// ... now suppose you called ble_nus_string_send somewhere
void foo(void) {
             uint32_t err_code = ble_nus_string_send(&amp;amp;m_nus, &amp;quot;Start now&amp;quot;, 9);
             APP_ERROR_CHECK(err_code);
             m_do_nus_iteration = true;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After the string &amp;quot;Start now&amp;quot; has successfully arrived at the central device,&lt;/p&gt;
&lt;p&gt;your peripheral now has the &lt;code&gt;BLE_EVT_TX_COMPLETE&lt;/code&gt; event.&lt;/p&gt;
&lt;p&gt;Check this &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s130.api.v1.0.0%2Fgroup___b_l_e___g_a_t_t_s___h_v_n___m_s_c.html&amp;amp;cp=2_7_2_1_1_2_3_0_13"&gt;sequence chart&lt;/a&gt; if you want more info about &lt;code&gt;BLE_EVT_TX_COMPLETE&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;extern bool m_do_nus_iteration;
// in case, your UART handling functions are at seperate source file

void on_ble_evt(ble_evt_t * p_ble_evt) {
        switch (p_ble_evt-&amp;gt;header.evt_id){
                       
                 case BLE_EVT_TX_COMPLETE: //at ble.h
                            // to distinguish whether this event happend due to ble_nus_string_send
                            if(m_do_nus_iteration) 
                                 my_nus_iter();
                                 break;
                 // for instance, I don&amp;#39;t want this to start when I send Heart Rate Service packets
// ...
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Lastly, this will send ABCD 4 times. After it succeeds sending, it will send again and again.&lt;/p&gt;
&lt;p&gt;Hope you get the idea here.&lt;/p&gt;
&lt;p&gt;However, I may have made some mistakes at the &lt;code&gt;my_nus_iter&lt;/code&gt; function, so take some inspections.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;extern uint16_t m_iter;
extern bool       m_do_nus_iteration;
void my_nus_iter(void) {

uint32_t err_code;

if(m_iter != 0) {
      err_code = ble_nus_string_send(&amp;amp;m_nus, &amp;quot;ABCD&amp;quot;, 4);
      if (err_code == BLE_ERROR_NO_TX_BUFFERS ||
              err_code == NRF_ERROR_INVALID_STATE ||
              err_code == BLE_ERROR_GATTS_SYS_ATTR_MISSING) {
              return;
} // I experienced BLE_ERROR_NO_TX_BUFFERS at here
    
else if (err_code != NRF_SUCCESS) {
       APP_ERROR_CHECK(err_code);
 }

if(m_iter-- == 0) m_do_nus_iteration = false; // finished sending X times. So stop.
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Hope you have understand how it works.&lt;/p&gt;
&lt;p&gt;A similar question &lt;a href="https://devzone.nordicsemi.com/question/70234/how-to-send-gyro-sensor-data-through-bluetoothble/"&gt;like this one&lt;/a&gt; can be a help to you.&lt;/p&gt;
&lt;p&gt;Also, I wish you to reveal what caused the reset.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;// Edited, Added at 23, March, 2016&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Sorry that I cannot give you the full code you want.&lt;/p&gt;
&lt;p&gt;However, I believe you can makes some changes and satisfy your needs.&lt;/p&gt;
&lt;p&gt;I referenced &lt;a href="https://devzone.nordicsemi.com/question/1741/dealing-large-data-packets-through-ble/"&gt;this link&lt;/a&gt; so this will be more helpful to you.&lt;/p&gt;
&lt;p&gt;-Best Regards, Mango922&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: my bluetooth gets disconnected while sending continous stream of data</title><link>https://devzone.nordicsemi.com/thread/47443?ContentTypeID=1</link><pubDate>Sun, 13 Mar 2016 08:06:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:88490cc0-374a-4a6a-aa17-587b8ed67ee5</guid><dc:creator>Deepak Kumar</dc:creator><description>&lt;p&gt;yes you are right, i am taking data as multiple of 3 byte which is a midi data. and timer i used to append data upto 20 byte because i can send maximum of 20 byte. while printing the output it gives output with correct timer value.
but after connecting to device the current time gives 0 due to which no data is being appened upto 20 byte.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: my bluetooth gets disconnected while sending continous stream of data</title><link>https://devzone.nordicsemi.com/thread/47442?ContentTypeID=1</link><pubDate>Sun, 13 Mar 2016 06:31:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b5fdf727-df44-4bf6-8bd7-a2c8aafd14ab</guid><dc:creator>MANGO</dc:creator><description>&lt;p&gt;Hmm, alright. I will just check again about your program is doing&lt;/p&gt;
&lt;p&gt;because I don&amp;#39;t know exactly your output is. I guess it&amp;#39;s creating frequency and a piezo or speaker makes sounds since you wrote &lt;code&gt;midiData&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You press keyboard button from your computer while you run a terminal program. -&amp;gt;&lt;/p&gt;
&lt;p&gt;UART Interrupt is called. Also, it calculates the elapsed time or whatever it is. -&amp;gt;&lt;/p&gt;
&lt;p&gt;Then &lt;code&gt;midiData&lt;/code&gt; is created and you want to see the value via BLE NUS at your phone, is it?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/**********************************/
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I will post an answer how to send multiple NUS packets soon.&lt;/p&gt;
&lt;p&gt;Before posting, please note me if I understood your code.&lt;/p&gt;
&lt;p&gt;Also, I think the reason of reset is that the timer or UART handling process is too long.&lt;/p&gt;
&lt;p&gt;I wish you can check when your code calls NVIC reset.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: my bluetooth gets disconnected while sending continous stream of data</title><link>https://devzone.nordicsemi.com/thread/47441?ContentTypeID=1</link><pubDate>Sat, 12 Mar 2016 18:32:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2f33c8c1-4589-4e39-9886-c7f06429fbe4</guid><dc:creator>Deepak Kumar</dc:creator><description>&lt;p&gt;hi,
actually i am new to ble development. i am printing only to see the output of my program.
i am sending the data using &lt;code&gt;sendData()&lt;/code&gt; function in the program&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void sendData(uint8_t data[],int index)
{
	uint32_t err_code;
	err_code = ble_nus_string_send(&amp;amp;m_nus, data, index);
                if (err_code != NRF_ERROR_INVALID_STATE)
                {
                    APP_ERROR_CHECK(err_code);
                }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;please explain me how can i send continuous data using this way. or is there any other way to do this.&lt;/p&gt;
&lt;p&gt;and yes &lt;code&gt;app_timer_cnt_diff_compute&lt;/code&gt; i am using from SDK 10 only. one more issue i am having regarding timer. after connecting to peripheral device timer always gives 0. can you explain me why it is so. and how can i get time after connecting.&lt;/p&gt;
&lt;p&gt;thanks!!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: my bluetooth gets disconnected while sending continous stream of data</title><link>https://devzone.nordicsemi.com/thread/47440?ContentTypeID=1</link><pubDate>Sat, 12 Mar 2016 17:46:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:55e7120b-527e-4b62-b76f-e7cf6f6869b7</guid><dc:creator>MANGO</dc:creator><description>&lt;p&gt;Oh, you are meaning that you continuously print debugging logs to the terminal program via UART?&lt;/p&gt;
&lt;p&gt;I thought you were sending BLE NUS packets to the central continuously. My mistake.&lt;/p&gt;
&lt;p&gt;Is the &lt;code&gt;app_timer_cnt_diff_compute&lt;/code&gt; from SDK 10 or is it your personal function?&lt;/p&gt;
&lt;p&gt;I used SDK 7.2 most of the time, so it will take a while to check.&lt;/p&gt;
&lt;p&gt;Then what function returns an error code to make your device to reset?&lt;/p&gt;
&lt;p&gt;Since I don&amp;#39;t know your purpose of your code (and will take quite a time),&lt;/p&gt;
&lt;p&gt;I think checking the error number will solve the problem.&lt;/p&gt;
&lt;p&gt;Place a breakpoint at &lt;code&gt;app_error_handler&lt;/code&gt; to check the error number and call stack before calling NVIC reset.&lt;/p&gt;
&lt;p&gt;If you are using IAR EWARM, go to view -&amp;gt; call stack (while debugging), and it will reveal what functions are called.&lt;/p&gt;
&lt;p&gt;By the way, are you using a Eval board or a custom board? Also do you use the scheduler from the SDK?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: my bluetooth gets disconnected while sending continous stream of data</title><link>https://devzone.nordicsemi.com/thread/47439?ContentTypeID=1</link><pubDate>Sat, 12 Mar 2016 17:32:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e8e90cf-28f4-4c76-9745-0c54ef66c458</guid><dc:creator>Deepak Kumar</dc:creator><description>&lt;p&gt;hi,
yes you are right i am using like this only in switch loop my data get updated each time. and device resets and disconnects.&lt;/p&gt;
&lt;p&gt;btw here is my code i am using to send data. and i am using 10 sdk NUS example.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;case APP_UART_DATA_READY:
            UNUSED_VARIABLE(app_uart_get(&amp;amp;data_array[index]));
            index++;
						push++;
						if(index%3 == 0)
						{
							count++;
							err_code = app_timer_cnt_get(&amp;amp;uart_time);
							APP_ERROR_CHECK(err_code);
	
							uart_time = app_timer_ms(uart_time);
							sent_time = app_timer_ms(sent_time);
							duration_time = app_timer_ms(duration_time);
							
							//diff
							err_code = app_timer_cnt_diff_compute(uart_time,sent_time,&amp;amp;duration_time);
							APP_ERROR_CHECK(err_code);
							
							SEGGER_RTT_printf(0, &amp;quot;uart:%d\tsent:%d\tduration:%d\n&amp;quot;,uart_time,sent_time,duration_time);
							//SEGGER_RTT_printf(0, &amp;quot;previous time:%d\n&amp;quot;,previous_time);
							//SEGGER_RTT_printf(0, &amp;quot;duration time:\t%d\n&amp;quot;,app_timer_ms(duration_time));
							
							
							
							
							SEGGER_RTT_printf(0, &amp;quot;current:%d\tsent:%d\n&amp;quot;,uart_time,sent_time);
								
								if(uart_time&amp;lt;sent_time+waiting_time)
								{
										const uint8_t* midiData = parseMIDItoAppleBle(3, data_array);
										for(int i=0;i&amp;lt;5;i++)
										{
												data[i] = midiData[i];
										}
										SEGGER_RTT_printf(0, &amp;quot;%x\t%x\t%x\t%x\t%x\tcnt:%d\n&amp;quot;,data[0], data[1],data[2],data[3], data[4],count);
										sendData(data,5);
										err_code = app_timer_cnt_get(&amp;amp;sent_time);
										APP_ERROR_CHECK(err_code);
								}
								
						
							index = 0;
							//rx_buf_num=0;

							//previous_time = current_time;
							preCount=count;
							//count=0;
						}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;thanks!!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: my bluetooth gets disconnected while sending continous stream of data</title><link>https://devzone.nordicsemi.com/thread/47438?ContentTypeID=1</link><pubDate>Sat, 12 Mar 2016 16:31:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3a5f8a98-84c3-4b59-9a3f-30af2ed038c6</guid><dc:creator>MANGO</dc:creator><description>&lt;p&gt;Hi, you might be using the NUS example. Can you tell me what SDK you are using?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Also can you tell me how you &amp;quot;send continuous stream&amp;quot;?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;As you know, when using &lt;code&gt;ble_nus_send_string&lt;/code&gt;, the maximum length is 20.&lt;/p&gt;
&lt;p&gt;Are you calling &lt;code&gt;ble_nus_send_string&lt;/code&gt; mutiple times like this?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;for(uint16_t k = 0 ; k &amp;lt; 1000 ; k++) {
      err_code = ble_nus_send_string(&amp;amp;m_nus, (uint8_t *) &amp;quot;Hello World&amp;quot;, 11);
      APP_ERROR_CHECK(err_code); // a bad way in my opinion
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Or are you using &lt;code&gt;BLE_EVT_TX_COMPLETE&lt;/code&gt; to taking care of this?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;You will get an BLE_EVT_TX_COMPLETE every time a packet you have queued for transmission.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;(&lt;a href="https://devzone.nordicsemi.com/question/2540/understanding-ble_evt_tx_complete/"&gt;ref. link&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;Before I answer your question, I expect you&amp;#39;ll get an error when calling &lt;code&gt;ble_nus_send_string&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;So the device resets and disconnects. Can you check the error code?&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>