<?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>Using NUS service to communicate between 2 devices</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/15144/using-nus-service-to-communicate-between-2-devices</link><description>Hi, i know maybe this question was asked before, but i have a particulary issue. 
 I have 2 devices connected through BLE. Just when them get connected i need to send a byte to identify who is the user of my application.The problem is that, i send this</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 15 Jul 2016 07:04:43 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/15144/using-nus-service-to-communicate-between-2-devices" /><item><title>RE: Using NUS service to communicate between 2 devices</title><link>https://devzone.nordicsemi.com/thread/57812?ContentTypeID=1</link><pubDate>Fri, 15 Jul 2016 07:04:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:66805059-f589-4558-8675-1f906eab20db</guid><dc:creator>Petter Myhre</dc:creator><description>&lt;p&gt;Antonio, if you have multiple unrelated questions, please ask them separately. Please consider taking our &lt;a href="https://devzone.nordicsemi.com/tour/"&gt;tour&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using NUS service to communicate between 2 devices</title><link>https://devzone.nordicsemi.com/thread/57811?ContentTypeID=1</link><pubDate>Thu, 14 Jul 2016 11:31:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:10d227af-bfa9-4524-90eb-537b1a619373</guid><dc:creator>Petter Myhre</dc:creator><description>&lt;p&gt;Great! Np :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using NUS service to communicate between 2 devices</title><link>https://devzone.nordicsemi.com/thread/57810?ContentTypeID=1</link><pubDate>Thu, 14 Jul 2016 11:24:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ff8ec221-ea0c-4fc6-b0f6-c79896e8a305</guid><dc:creator>Antonio</dc:creator><description>&lt;p&gt;Thank you very much PETTER MYHRE, you have solved my problem.. the problem was that when that i assign a NULL attribute handle. i going to copy the modified code to show you what i did. THANK YOU.&lt;/p&gt;
&lt;p&gt;Connected event:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    case BLE_GAP_EVT_CONNECTED:
            {
    		
    					  
    					
    //					  erro_code = ble_nus_c_handles_assign(&amp;amp;m_ble_nus_c, p_gap_evt-&amp;gt;conn_handle, NULL);
    //            APP_ERROR_CHECK(erro_code);
    										
    						erro_code = ble_db_discovery_start(&amp;amp;m_ble_db_discovery, p_gap_evt-&amp;gt;conn_handle);
                APP_ERROR_CHECK(erro_code);
    					  logi(&amp;quot;me conecte a periferico nus &amp;quot;);
    					if(erro_code != NRF_SUCCESS){
    							nrf_gpio_pin_write(24,0);
    					    nrf_delay_ms(1000);
    			        nrf_gpio_pin_write(24,1);
    						}
    					 
    						
    					  logi(&amp;quot;mande el dato &amp;quot;);
    					 // Update LEDs status, and check if we should be looking for more
               // peripherals to connect to.
                LEDS_ON(CENTRAL_CONNECTED_LED);
                LEDS_OFF(CENTRAL_SCANNING_LED);
    						
            } break; // BLE_GAP_EVT_CONNECTED


/**@snippet [Handling events from the ble_nus_c module] */ 
static void ble_nus_c_evt_handler(ble_nus_c_t * p_ble_nus_c, const ble_nus_c_evt_t * p_ble_nus_evt)
{
		static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
		data_array[0] = 0x02;
		static uint8_t index = 19;
    uint32_t err_code;
    switch (p_ble_nus_evt-&amp;gt;evt_type)
    {
        case BLE_NUS_C_EVT_DISCOVERY_COMPLETE:
            err_code = ble_nus_c_handles_assign(p_ble_nus_c, p_ble_nus_evt-&amp;gt;conn_handle, &amp;amp;p_ble_nus_evt-&amp;gt;handles);
            APP_ERROR_CHECK(err_code);

            err_code = ble_nus_c_rx_notif_enable(p_ble_nus_c);
            APP_ERROR_CHECK(err_code);
//            APPL_LOG(&amp;quot;The device has the Nordic UART Service\r\n&amp;quot;);
				 
						err_code = ble_nus_c_string_send(&amp;amp;m_ble_nus_c, data_array, index);
					  if(err_code == NRF_SUCCESS){
							nrf_gpio_pin_write(24,0);
					    nrf_delay_ms(100);
			        nrf_gpio_pin_write(24,1);
						}
            break;
    
		
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Handling events from the ble_nus_c module:			&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void ble_nus_c_evt_handler(ble_nus_c_t * p_ble_nus_c, const ble_nus_c_evt_t * p_ble_nus_evt)
{
		static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
		data_array[0] = 0x02;
		static uint8_t index = 19;
    uint32_t err_code;
    switch (p_ble_nus_evt-&amp;gt;evt_type)
    {
        case BLE_NUS_C_EVT_DISCOVERY_COMPLETE:
            err_code = ble_nus_c_handles_assign(p_ble_nus_c, p_ble_nus_evt-&amp;gt;conn_handle, &amp;amp;p_ble_nus_evt-&amp;gt;handles);
            APP_ERROR_CHECK(err_code);

            err_code = ble_nus_c_rx_notif_enable(p_ble_nus_c);
            APP_ERROR_CHECK(err_code);
//            APPL_LOG(&amp;quot;The device has the Nordic UART Service\r\n&amp;quot;);
				 
						err_code = ble_nus_c_string_send(&amp;amp;m_ble_nus_c, data_array, index);
					  if(err_code == NRF_SUCCESS){
							nrf_gpio_pin_write(24,0);
					    nrf_delay_ms(100);
			        nrf_gpio_pin_write(24,1);
						}
            break;
        
				
				
        case BLE_NUS_C_EVT_NUS_RX_EVT:
            for (uint32_t i = 0; i &amp;lt; p_ble_nus_evt-&amp;gt;data_len; i++)
            {
                while(app_uart_put( p_ble_nus_evt-&amp;gt;p_data[i]) != NRF_SUCCESS);
            }
            break;
        
        case BLE_NUS_C_EVT_DISCONNECTED:
//            APPL_LOG(&amp;quot;Disconnected\r\n&amp;quot;);
            scan_start();
            break;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using NUS service to communicate between 2 devices</title><link>https://devzone.nordicsemi.com/thread/57809?ContentTypeID=1</link><pubDate>Thu, 14 Jul 2016 11:00:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:94ceb9f7-3294-4d0d-a5cb-c174f6d07c9f</guid><dc:creator>Petter Myhre</dc:creator><description>&lt;p&gt;Why are you calling ble_nus_c_handles_assign() with NULL as the last argument? And why are you calling it before ble_db_discovery_start()? Shouldn&amp;#39;t you actually discover the services and wait for the BLE_NUS_C_EVT_DISCOVERY_COMPLETE event before you call ble_nus_c_handles_assign() with the actual attribute handles of the relevant characteristics and descriptors? So, ble_nus_c_string_send() return sNRF_SUCCESS but the nus_data_handler() is not called, do you receive a BLE_GATTS_EVT_WRITE event?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>