<?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>ble_nus_data_send returns 0x5 error code</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/59832/ble_nus_data_send-returns-0x5-error-code</link><description>Hello, I wanted to send data over peripheral device to the central device by using ble UART example. I used ble_nus_data_send() function in main(void) function. I have checked if the data was sent or not . ble_nus_data_send() returned 0x5 instead of NRF_SUCCESS</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 16 Apr 2020 16:14:18 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/59832/ble_nus_data_send-returns-0x5-error-code" /><item><title>RE: ble_nus_data_send returns 0x5 error code</title><link>https://devzone.nordicsemi.com/thread/245075?ContentTypeID=1</link><pubDate>Thu, 16 Apr 2020 16:14:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c1d3c00c-728c-4ecd-b0f1-4b11b114a039</guid><dc:creator>OpenCircuit</dc:creator><description>&lt;p&gt;I can see data that I sent&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble_nus_data_send returns 0x5 error code</title><link>https://devzone.nordicsemi.com/thread/244828?ContentTypeID=1</link><pubDate>Wed, 15 Apr 2020 23:11:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d08e0ac5-9def-4864-8acd-67ad70c722ee</guid><dc:creator>OpenCircuit</dc:creator><description>&lt;p&gt;Now I get the logic. Thank you Simon, it worked ! Now ble_nus_data_send returns 0x0.&lt;br /&gt;Could you please tell me that how I can see the data I sent in central side ? &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble_nus_data_send returns 0x5 error code</title><link>https://devzone.nordicsemi.com/thread/244826?ContentTypeID=1</link><pubDate>Wed, 15 Apr 2020 22:12:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a0286e5d-0a38-4a34-86f4-fa9d477ed6c2</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;The question is not where you call it, the question is when you call it. You should call it after&amp;nbsp;p_client-&amp;gt;is_notification_enabled = true runs (after the log &lt;em&gt;&amp;quot;Notification enabled&amp;quot;&lt;/em&gt;)&lt;/p&gt;
&lt;p&gt;Here is one approach:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Utilize the event type&amp;nbsp;BLE_NUS_EVT_COMM_STARTED, which shows that notifications has been enabled:&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief   Nordic UART Service event types. */
typedef enum
{
    BLE_NUS_EVT_RX_DATA,      /**&amp;lt; Data received. */
    BLE_NUS_EVT_TX_RDY,       /**&amp;lt; Service is ready to accept new data to be transmitted. */
    BLE_NUS_EVT_COMM_STARTED, /**&amp;lt; Notification has been enabled. */
    BLE_NUS_EVT_COMM_STOPPED, /**&amp;lt; Notification has been disabled. */
} ble_nus_evt_type_t;
&lt;/pre&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In&amp;nbsp;nus_data_handler() add the following piece of code:&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void nus_data_handler(ble_nus_evt_t * p_evt)
{

    if (p_evt-&amp;gt;type == BLE_NUS_EVT_COMM_STARTED)  //Add this
    {                                             //Add this

        
        //Call ble_nus_data_send() here

    }
    

    if (p_evt-&amp;gt;type == BLE_NUS_EVT_RX_DATA)
    {
        uint32_t err_code;

        NRF_LOG_DEBUG(&amp;quot;Received data from BLE NUS. Writing data on UART.&amp;quot;);
        NRF_LOG_HEXDUMP_DEBUG(p_ev...
        .
        .
        .&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble_nus_data_send returns 0x5 error code</title><link>https://devzone.nordicsemi.com/thread/244821?ContentTypeID=1</link><pubDate>Wed, 15 Apr 2020 21:19:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f0974e0d-0d53-485e-95e5-c3c22a330dda</guid><dc:creator>OpenCircuit</dc:creator><description>&lt;p&gt;Thanks for explanation. Yes, I am using ble_app_c_uart. I can say that notification is enabled. &lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;if (ble_srv_is_notification_enabled(p_evt_write-&amp;gt;data))
            {
                NRF_LOG_INFO(&amp;quot;Notification enabled.&amp;quot;);
                p_client-&amp;gt;is_notification_enabled = true;
                evt.type                          = BLE_NUS_EVT_COMM_STARTED;
            }&lt;/pre&gt;&lt;br /&gt;After this, I get the info below in RTT viewer from the central side when I power the peripheral device:&lt;/p&gt;
&lt;p&gt;00&amp;gt; &amp;lt;info&amp;gt; app: BLE UART central example started.&lt;br /&gt;00&amp;gt; &amp;lt;info&amp;gt; app: Connecting to target 893473D394EE&lt;br /&gt;00&amp;gt; &amp;lt;info&amp;gt; app: ATT MTU exchange completed.&lt;br /&gt;00&amp;gt; &amp;lt;info&amp;gt; app: Ble NUS max data length set to 0x14(20)&lt;br /&gt;00&amp;gt; &amp;lt;info&amp;gt; app: Discovery complete.&lt;br /&gt;00&amp;gt; &amp;lt;info&amp;gt; app: Connected to device with Nordic UART Service.&lt;/p&gt;
&lt;p&gt;And this is the info from peripheral side when I call my function in BLE_GAP_EVT_CONNECTED &lt;br /&gt;&lt;br /&gt;00&amp;gt; &amp;lt;info&amp;gt; app: Debug logging for UART over RTT started.&lt;br /&gt;00&amp;gt; &amp;lt;info&amp;gt; app: Connected&lt;br /&gt;00&amp;gt; &amp;lt;info&amp;gt; app: ble_nus_data_send returned 0x8&lt;br /&gt;00&amp;gt; &amp;lt;info&amp;gt; app: Data len is set to 0x14(20)&lt;br /&gt;00&amp;gt; &amp;lt;info&amp;gt; ble_nus: Notification enabled.&lt;br /&gt;&lt;br /&gt;I know that if ble_nus_data_send() function returns NRF_SUCCESS, it means data is sent. &lt;br /&gt;My question is that where should I call send_data function I mentioned. ( if I wrote send_data function correctly ). I tried calling it in main() function in a while loop and in&amp;nbsp; BLE_GAP_EVT_CONNECTED, but both of them didn&amp;#39;t work.&lt;br /&gt;&lt;br /&gt;Best Regards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble_nus_data_send returns 0x5 error code</title><link>https://devzone.nordicsemi.com/thread/244773?ContentTypeID=1</link><pubDate>Wed, 15 Apr 2020 14:29:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3e64ee96-e5a9-44fe-a1d9-d88c5cc719a9</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;The reason it is failing is that the client (often the central) hasn&amp;#39;t enabled notifications yet. In order to send data from the server (the device where the services and characteristics are stored and it is often the peripheral device) to the client, notifications need to be enabled, which is done by writing to the &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/561/what-does-cccd-mean"&gt;CCCD&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I assume you are using the ble_app_uart central and the ble_app_uart peripheral examples. In that case, the ble_app_uart central example will enable notifications after service discovery is completed. Look at&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;em&gt;\nRF5_SDK_16.0.0\examples\ble_central\ble_app_uart_c\main.c--&amp;gt;ble_nus_c_evt_handler()--&amp;gt;BLE_NUS_C_EVT_DISCOVERY_COMPLETE--&amp;gt;ble_nus_c_tx_notif_enable()&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void ble_nus_c_evt_handler(ble_nus_c_t * p_ble_nus_c, ble_nus_c_evt_t const * p_ble_nus_evt)
{
    ret_code_t err_code;

    switch (p_ble_nus_evt-&amp;gt;evt_type)
    {
        case BLE_NUS_C_EVT_DISCOVERY_COMPLETE:
            NRF_LOG_INFO(&amp;quot;Discovery complete.&amp;quot;);
            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_tx_notif_enable(p_ble_nus_c);
            APP_ERROR_CHECK(err_code);
            NRF_LOG_INFO(&amp;quot;Connected to device with Nordic UART Service.&amp;quot;);
            break;&lt;/pre&gt;&lt;/em&gt;&lt;em&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;When the ble_app_uart peripheral device receives this write, the function on_write() in&amp;nbsp;&lt;em&gt;\nRF5_SDK_16.0.0\components\ble\ble_services\ble_nus\ble_nus.c&amp;nbsp;&lt;/em&gt;will get triggered, and&amp;nbsp;&amp;nbsp;p_client-&amp;gt;is_notification_enabled is&amp;nbsp; set to &amp;quot;true&amp;quot;:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void on_write(ble_nus_t * p_nus, ble_evt_t const * p_ble_evt)
{
    .
    .
    .

    if ((p_evt_write-&amp;gt;handle == p_nus-&amp;gt;tx_handles.cccd_handle) &amp;amp;&amp;amp;
        (p_evt_write-&amp;gt;len == 2))
    {
        if (p_client != NULL)
        {
            if (ble_srv_is_notification_enabled(p_evt_write-&amp;gt;data))
            {
                p_client-&amp;gt;is_notification_enabled = true;
                evt.type                          = BLE_NUS_EVT_COMM_STARTED;
            }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;After this happens, you can send data from the server (ble_app_uart peripheral) to the client (ble_app_uart central).&lt;/p&gt;
&lt;p&gt;&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><item><title>RE: ble_nus_data_send returns 0x5 error code</title><link>https://devzone.nordicsemi.com/thread/244308?ContentTypeID=1</link><pubDate>Mon, 13 Apr 2020 22:06:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f39109c4-2de4-4665-bd21-dd970cee8102</guid><dc:creator>OpenCircuit</dc:creator><description>&lt;p&gt;Hello Simon,&lt;br /&gt;&lt;br /&gt;I am still having this problem. I tried with this basic function:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void send_data(void)
{
    uint32_t err_code;
    uint16_t length = 6;
    NRF_LOG_INFO(&amp;quot;Start&amp;quot;);
    uint8_t array[6];
    array[0] = &amp;#39;h&amp;#39;;
    array[1] = &amp;#39;e&amp;#39;;
    array[2] = &amp;#39;l&amp;#39;;
    array[3] = &amp;#39;l&amp;#39;;
    array[4] = &amp;#39;o&amp;#39;;
    array[5] = &amp;#39;\n&amp;#39;;

    err_code = ble_nus_data_send(&amp;amp;m_nus, array, &amp;amp;length, m_conn_handle);
    NRF_LOG_INFO (&amp;quot;ble_nus_data_send returned 0x%x&amp;quot;, err_code)
    
} 
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;I calIed this function in BLE_GAP_EVT_CONNECTED case, but got same error (0x8). I think it is a mistake calling this function in BLE_GAP_EVT_CONNECTED. &lt;br /&gt;I tought that maybe I should create function in uart_event_handle() function, but this function is about receiving data, isn&amp;#39;t it ? &lt;br /&gt;I also checked if my notifications are enabled or not. I followed instructions from: &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/42244/nrf_error_invalid_state-when-calling-ble_nus_data_send-after-connection-is-established"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/42244/nrf_error_invalid_state-when-calling-ble_nus_data_send-after-connection-is-established&lt;/a&gt; &lt;br /&gt;I can see that notifications are enabled.&lt;br /&gt;I would try send data with button action in bsp_event_handler() function, but I just want to send data after connection.&lt;br /&gt;I hope that I specified my problem clearly. If my function has no error, I would like to know that where should I call my function or create in somewhere else.&lt;/p&gt;
&lt;p&gt;Best Regards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble_nus_data_send returns 0x5 error code</title><link>https://devzone.nordicsemi.com/thread/243832?ContentTypeID=1</link><pubDate>Tue, 07 Apr 2020 09:00:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c28949dc-793b-40b1-826d-a723649a5c40</guid><dc:creator>OpenCircuit</dc:creator><description>&lt;p&gt;No problem, I will be waiting. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble_nus_data_send returns 0x5 error code</title><link>https://devzone.nordicsemi.com/thread/243826?ContentTypeID=1</link><pubDate>Tue, 07 Apr 2020 08:42:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:46946cf3-9a00-4a0d-bae6-c2288c36a910</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;&lt;span&gt;I am sorry for the delay&lt;/span&gt;&lt;span&gt;,&amp;nbsp;&lt;/span&gt;&lt;span&gt;The staffing is reduced during easter due to holidays and I will be gone this week, but I will be back Tuesday next week and will look at your ticket then.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Simon&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble_nus_data_send returns 0x5 error code</title><link>https://devzone.nordicsemi.com/thread/243392?ContentTypeID=1</link><pubDate>Fri, 03 Apr 2020 11:56:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a832bd6c-e7f8-4e4c-96fe-676d35581c79</guid><dc:creator>OpenCircuit</dc:creator><description>&lt;p&gt;Sorry, I declared the flag as global, but nothing changed. It doesn&amp;#39;t even say &amp;quot;Debug logging for UART over RTT started.&amp;quot;&amp;nbsp; I think it has something to do with while loop. I tried setting the flag to = 0 after the if branch, but it didn&amp;#39;t work neither.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble_nus_data_send returns 0x5 error code</title><link>https://devzone.nordicsemi.com/thread/243382?ContentTypeID=1</link><pubDate>Fri, 03 Apr 2020 11:34:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5e767700-2a36-4755-a090-067d68331220</guid><dc:creator>Sunil vignesh</dc:creator><description>&lt;p&gt;no it&amp;#39;s wrong.&lt;/p&gt;
&lt;p&gt;you have to declare the flag in global. after the header files&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble_nus_data_send returns 0x5 error code</title><link>https://devzone.nordicsemi.com/thread/243375?ContentTypeID=1</link><pubDate>Fri, 03 Apr 2020 11:05:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e4a1a162-cdae-47bc-9857-f7485a3ba824</guid><dc:creator>OpenCircuit</dc:creator><description>&lt;p&gt;int main(void)&lt;/p&gt;
&lt;p&gt;{&lt;br /&gt;&lt;br /&gt;..&lt;br /&gt;&lt;br /&gt;static uint8_t data_array[BLE_NUS_MAX_DATA_LEN] = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint16_t length = 11;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (1) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int flag = 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( flag == true ) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nrf_delay_us(2000);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ble_nus_data_send(&amp;amp;m_nus, data_array, &amp;amp;length, m_conn_handle);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t err_code = ble_nus_data_send(&amp;amp;m_nus, data_array, &amp;amp;length, m_conn_handle);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NRF_LOG_INFO (&amp;quot;ble_nus_data_send returned 0x%x&amp;quot;, err_code)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;..&lt;/p&gt;
&lt;p&gt;}}}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;this time nothing appears on RTT viewer. It wanted me to declare flag again.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble_nus_data_send returns 0x5 error code</title><link>https://devzone.nordicsemi.com/thread/243371?ContentTypeID=1</link><pubDate>Fri, 03 Apr 2020 10:46:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bf56cd99-17d9-4fd5-b4da-7df2a3a44d11</guid><dc:creator>Sunil vignesh</dc:creator><description>&lt;p&gt;write while loop inside main function &lt;/p&gt;
&lt;p&gt;int main (void)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;..&lt;/p&gt;
&lt;p&gt;..&lt;/p&gt;
&lt;p&gt;While(1)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;if(flag)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;}}}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble_nus_data_send returns 0x5 error code</title><link>https://devzone.nordicsemi.com/thread/243365?ContentTypeID=1</link><pubDate>Fri, 03 Apr 2020 10:31:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dbeea29a-2815-4856-a80e-9942c8d86963</guid><dc:creator>OpenCircuit</dc:creator><description>&lt;p&gt;I wrote like this: &lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    uint32_t err_code;
    static uint8_t data_array[BLE_NUS_MAX_DATA_LEN] = &amp;quot;Hello World&amp;quot;;
    uint16_t length = 11;
    int flag = 0;

    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            flag == true;
            NRF_LOG_INFO(&amp;quot;Connected&amp;quot;);
            err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
            APP_ERROR_CHECK(err_code);
            m_conn_handle = p_ble_evt-&amp;gt;evt.gap_evt.conn_handle;
            err_code = nrf_ble_qwr_conn_handle_assign(&amp;amp;m_qwr, m_conn_handle);
            APP_ERROR_CHECK(err_code);

            break;

        case BLE_GAP_EVT_DISCONNECTED:
            flag == false;
            NRF_LOG_INFO(&amp;quot;Disconnected&amp;quot;);
            // LED indication will be changed when advertising starts.
            m_conn_handle = BLE_CONN_HANDLE_INVALID;
            break;
        &lt;/pre&gt;&lt;br /&gt;and wrote while loop like this:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;while (1);
        if ( flag == true ) {
        nrf_delay_us(2000);
        ble_nus_data_send(&amp;amp;m_nus, data_array, &amp;amp;length, m_conn_handle);
        uint32_t err_code = ble_nus_data_send(&amp;amp;m_nus, data_array, &amp;amp;length, m_conn_handle);

        NRF_LOG_INFO (&amp;quot;ble_nus_data_send returned 0x%x&amp;quot;, err_code)
        }
&lt;/pre&gt;&lt;br /&gt;I don&amp;#39;t know where to put while loop set. Maybe I wrote wrong.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble_nus_data_send returns 0x5 error code</title><link>https://devzone.nordicsemi.com/thread/243353?ContentTypeID=1</link><pubDate>Fri, 03 Apr 2020 09:42:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a6c17912-8346-4cc2-867e-6a7fe29c5e12</guid><dc:creator>Sunil vignesh</dc:creator><description>&lt;p&gt;you can set the a flag = true&amp;nbsp; there (BLE_GAP_EVT_CONNECTED)&lt;/p&gt;
&lt;p&gt;and set flag as false in (EVT_ DISCONNECTED )&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;and in while loop set&lt;/p&gt;
&lt;p&gt;if (flag == true)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;&amp;nbsp; with delay of 2 sec&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;write code here.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble_nus_data_send returns 0x5 error code</title><link>https://devzone.nordicsemi.com/thread/243349?ContentTypeID=1</link><pubDate>Fri, 03 Apr 2020 09:31:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:06062d6b-630f-4375-b8c5-aebc59097921</guid><dc:creator>OpenCircuit</dc:creator><description>&lt;p&gt;This time it returns 0x8 which means &amp;quot;Invalid state, operation disallowed in this state.&amp;quot;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define 	NRF_ERROR_INVALID_STATE   (NRF_ERROR_BASE_NUM + 8)&lt;/pre&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    uint32_t err_code;
    static uint8_t data_array[BLE_NUS_MAX_DATA_LEN] = &amp;quot;Hello World&amp;quot;;
    uint16_t length = 11;

    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            NRF_LOG_INFO(&amp;quot;Connected&amp;quot;);
            err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
            APP_ERROR_CHECK(err_code);
            m_conn_handle = p_ble_evt-&amp;gt;evt.gap_evt.conn_handle;
            err_code = nrf_ble_qwr_conn_handle_assign(&amp;amp;m_qwr, m_conn_handle);
            APP_ERROR_CHECK(err_code);

            ble_nus_data_send(&amp;amp;m_nus, data_array, &amp;amp;length, m_conn_handle);
            uint32_t err_code = ble_nus_data_send(&amp;amp;m_nus, data_array, &amp;amp;length, m_conn_handle);

            NRF_LOG_INFO (&amp;quot;ble_nus_data_send returned 0x%x&amp;quot;, err_code)
             
       
            break;&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble_nus_data_send returns 0x5 error code</title><link>https://devzone.nordicsemi.com/thread/243337?ContentTypeID=1</link><pubDate>Fri, 03 Apr 2020 09:03:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:202b0927-0ba5-4fb4-950e-3cac450aebbf</guid><dc:creator>Sunil vignesh</dc:creator><description>&lt;p&gt;yes, you can call the function one after the BLE_ CONNECTED &lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    uint32_t err_code;

    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            NRF_LOG_INFO(&amp;quot;Connected&amp;quot;);
            err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
            APP_ERROR_CHECK(err_code);
            m_conn_handle = p_ble_evt-&amp;gt;evt.gap_evt.conn_handle;
            err_code = nrf_ble_qwr_conn_handle_assign(&amp;amp;m_qwr, m_conn_handle);
            APP_ERROR_CHECK(err_code);
            ..
            data_send();// you call the function ...
            
            break;
....
....
...
}
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble_nus_data_send returns 0x5 error code</title><link>https://devzone.nordicsemi.com/thread/243333?ContentTypeID=1</link><pubDate>Fri, 03 Apr 2020 08:56:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:313c1713-33ea-4e48-9bf8-6b7ce88900e2</guid><dc:creator>OpenCircuit</dc:creator><description>&lt;p&gt;Yeah, you are right. ble_nus_data_send()&amp;nbsp; function is executed before the peripheral and central device connect each other. That&amp;#39;s why I get this info on RTT viewer : &lt;/p&gt;
&lt;p&gt;00&amp;gt; &amp;lt;info&amp;gt; app: Debug logging for UART over RTT started.&lt;br /&gt;00&amp;gt; &amp;lt;info&amp;gt; app: ble_nus_data_send returned 0x5&lt;br /&gt;00&amp;gt; &amp;lt;info&amp;gt; app: Connected&lt;br /&gt;00&amp;gt; &amp;lt;info&amp;gt; app: Data len is set to 0x14(20)&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;The function needs to be executed after the devices connect each other. Should I call the function in somewhere else ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble_nus_data_send returns 0x5 error code</title><link>https://devzone.nordicsemi.com/thread/243321?ContentTypeID=1</link><pubDate>Fri, 03 Apr 2020 08:02:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e170087-fcf9-4545-aec6-275e1ca35df6</guid><dc:creator>Sunil vignesh</dc:creator><description>&lt;p&gt;I am not found any error in the code. rather i found the cause of 0x5 because . at the time of sending the device didn&amp;#39;t connected with central or mobile.&lt;/p&gt;
&lt;p&gt;i just you to send the data once you connected with the central.&lt;/p&gt;
&lt;p&gt;the peripheral need to know the device connected to other and then you send the data it will be success&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble_nus_data_send returns 0x5 error code</title><link>https://devzone.nordicsemi.com/thread/243309?ContentTypeID=1</link><pubDate>Fri, 03 Apr 2020 07:12:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:35c0c6fa-43ab-4340-a9fc-39c5639ef0f5</guid><dc:creator>OpenCircuit</dc:creator><description>&lt;p&gt;Okay, let me know if I you want to check another function. Do I have to edit uart_event_handle() function ?&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;int main(void)
{
    bool erase_bonds;

    // Initialize.
    uart_init();
    log_init();
    timers_init();
    buttons_leds_init(&amp;amp;erase_bonds);
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();

    // Start execution.
    printf(&amp;quot;\r\nUART started.\r\n&amp;quot;);
    NRF_LOG_INFO(&amp;quot;Debug logging for UART over RTT started.&amp;quot;);
    advertising_start();

    static uint8_t data_array[BLE_NUS_MAX_DATA_LEN] = &amp;quot;Hello World&amp;quot;;
        uint16_t length = 11;

        ble_nus_data_send(&amp;amp;m_nus, data_array, &amp;amp;length, m_conn_handle);
        uint32_t err_code = ble_nus_data_send(&amp;amp;m_nus, data_array, &amp;amp;length, m_conn_handle);

        NRF_LOG_INFO (&amp;quot;ble_nus_data_send returned 0x%x&amp;quot;, err_code)


    // Enter main loop.
    for (;;)
    {
        idle_state_handle();
    }
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble_nus_data_send returns 0x5 error code</title><link>https://devzone.nordicsemi.com/thread/243294?ContentTypeID=1</link><pubDate>Fri, 03 Apr 2020 04:22:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:408c5974-d67a-475c-ab06-243d2a9e03a5</guid><dc:creator>Sunil vignesh</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;the error says &amp;quot;not found &amp;quot;. may be connection lost&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define NRF_ERROR_NOT_FOUND                   (NRF_ERROR_BASE_NUM + 5)  ///&amp;lt; Not found&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;you can post the code here. let it check&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>