<?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>nRF hangs when sending second UDP package using thread</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/63914/nrf-hangs-when-sending-second-udp-package-using-thread</link><description>Hi all, 
 Using the thread CLI example (on a PCA10056 board) as a starting point I would like nodes to connect automatically to a thread mesh when booting. I then want to use this mesh to exchange UDP packets. 
 The joining of the thread network works</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 09 Aug 2021 12:18:12 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/63914/nrf-hangs-when-sending-second-udp-package-using-thread" /><item><title>RE: nRF hangs when sending second UDP package using thread</title><link>https://devzone.nordicsemi.com/thread/323996?ContentTypeID=1</link><pubDate>Mon, 09 Aug 2021 12:18:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bf77170f-9ec4-4987-bd43-c92b7c1dd2be</guid><dc:creator>slimhoussam</dc:creator><description>&lt;p&gt;I managed to fix this issue, I&amp;#39;ve just called&amp;nbsp;otCliConsoleInputLine() function after initialization phase within main() function of the receiver node :&lt;/p&gt;
&lt;p&gt;int main(int argc, char *argv[])&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;/*Initialization*/&lt;/p&gt;
&lt;p&gt;log_init();&lt;br /&gt; scheduler_init();&lt;br /&gt; timer_init();&lt;br /&gt; leds_init();&lt;br /&gt; thread_instance_init();&lt;/p&gt;
&lt;p&gt;/*udp open*/&lt;/p&gt;
&lt;p&gt;char cli_cmd[] = &amp;quot;udp open\r\n&amp;quot;;&lt;br /&gt; otCliConsoleInputLine(&lt;span&gt;cli_cmd&lt;/span&gt;, strlen(&lt;span&gt;cli_cmd&lt;/span&gt;));&lt;/p&gt;
&lt;p&gt;&lt;span&gt;/*udp bind :: 1994*/&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;char cli_cmd_2[] = &amp;quot;udp bind :: 1994\r\n&amp;quot;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;otCliConsoleInputLine(&lt;/span&gt;&lt;span&gt;cli_cmd_2&lt;/span&gt;&lt;span&gt;, strlen(&lt;/span&gt;&lt;span&gt;cli_cmd_2&lt;/span&gt;&lt;span&gt;));&lt;/span&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;/p&gt;
&lt;p&gt;It works perfectly.&lt;/p&gt;
&lt;p&gt;Kind Regards,&lt;/p&gt;
&lt;p&gt;Houssam&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF hangs when sending second UDP package using thread</title><link>https://devzone.nordicsemi.com/thread/323129?ContentTypeID=1</link><pubDate>Tue, 03 Aug 2021 13:22:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e147caf2-8a34-490b-9ec3-a79cbc1360cc</guid><dc:creator>slimhoussam</dc:creator><description>&lt;p&gt;Hello Everybody,&lt;/p&gt;
&lt;p&gt;It works perfectly for me, however the receiver node should have&amp;nbsp;&lt;span&gt;&amp;quot;udp open&amp;quot; and &amp;quot;udp bind :: 1994&amp;quot;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;In order to add this feature directly to main.c, so that the receiver node will get the Hello message without using CLI commands &amp;quot;udp open&amp;quot; and &amp;quot;udp bind :: 1994&amp;quot;, I have defined a function receive_udp_command() and call it in main loop :&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;*************************************************************************************************************************************&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;*************************************************************************************************************************************&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;otError receive_udp_command(void)&lt;br /&gt;{&lt;br /&gt; otError error = OT_ERROR_NONE;&lt;/p&gt;
&lt;p&gt;otUdpSocket * socket;&lt;br /&gt; otMessageInfo messageInfo;&lt;br /&gt; &lt;br /&gt; otSockAddr addr;&lt;/p&gt;
&lt;p&gt;memset(&amp;amp;addr, 0, sizeof(addr));&lt;br /&gt; memset(socket, 0, sizeof(otSockAddr));&lt;/p&gt;
&lt;p&gt;memset(&amp;amp;messageInfo, 0, sizeof(messageInfo));&lt;/p&gt;
&lt;p&gt;error = otUdpOpen(thread_ot_instance_get(), socket, port_data_callback, NULL);&lt;br /&gt; if (error != OT_ERROR_NONE )&lt;br /&gt; {&lt;br /&gt; NRF_LOG_INFO(&amp;quot;otUdpOpen err = %u&amp;quot;, error);&lt;br /&gt; return error;&lt;br /&gt; }&lt;br /&gt; if (error == OT_ERROR_NONE )&lt;br /&gt; {&lt;br /&gt; NRF_LOG_INFO(&amp;quot;otUdpOpen SUCCESS!&amp;quot;);&lt;br /&gt; addr.mPort = UDP_PORT ;&lt;br /&gt; error = otUdpBind(socket, &amp;amp;addr);&lt;br /&gt; NRF_LOG_INFO(&amp;quot;Udp bind Success !&amp;quot;);&lt;br /&gt; return error;&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;return error;&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&lt;span&gt;*************************************************************************************************************************************&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;*************************************************************************************************************************************&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;This function is called properly in main loop, unfortunately, I didn&amp;#39;t receive Hello message after pushing the button on sender node, any help or examples ?&lt;/p&gt;
&lt;p&gt;Thank you so much :)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Kind Regards,&lt;/p&gt;
&lt;p&gt;Houssam&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF hangs when sending second UDP package using thread</title><link>https://devzone.nordicsemi.com/thread/264939?ContentTypeID=1</link><pubDate>Mon, 17 Aug 2020 18:42:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f5ab9518-6364-4ae5-9d65-a4bf3e0283d2</guid><dc:creator>Farhang</dc:creator><description>&lt;p&gt;Glad to hear it was helpful. I still believe it was the repeated calling of&amp;nbsp;&lt;span&gt;otUdpSend() in while(true) that messed up the stack.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF hangs when sending second UDP package using thread</title><link>https://devzone.nordicsemi.com/thread/264692?ContentTypeID=1</link><pubDate>Sat, 15 Aug 2020 12:36:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e8b34a3c-a3c8-4208-a375-a3b801d53a69</guid><dc:creator>hubert_11</dc:creator><description>&lt;p&gt;Sorry for the late response, but using your code it doesn&amp;#39;t hang. Not sure what the problem was, but now it works!&lt;/p&gt;
&lt;p&gt;thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF hangs when sending second UDP package using thread</title><link>https://devzone.nordicsemi.com/thread/261471?ContentTypeID=1</link><pubDate>Thu, 23 Jul 2020 21:47:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c357e0fd-3aaf-41f4-a8f7-9388749817d0</guid><dc:creator>Farhang</dc:creator><description>&lt;p&gt;It could be that you&amp;#39;re calling&amp;nbsp;otUdpSend() in essentially what is a while(true) loop. The function may not be re-entrant or may need to deal with one message at a time. I suppose with the&amp;nbsp;HandleUdpReceive() callback your code will be notified when a transaction is done.&lt;/p&gt;
&lt;p&gt;Can you post what you have in&amp;nbsp;&lt;span&gt;HandleUdpReceive()?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;And if you&amp;#39;re debugging, hitting the pause or stop on the debugger controls could help you understand where your code is stuck, with the help of &amp;quot;call stack&amp;quot; feature. IAR embedded worked for me catching a couple of issues this way. You may want to turn optimization down to Medium if set to High.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I am on this same path to send a multicast message via UDP..&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I have tied Button 1 on nRF52830DK to sending the message, every time i push that all other nodes that have &amp;quot;udp open&amp;quot; and &amp;quot;upd bind :: 1994&amp;quot; will receive the &amp;quot;Hello&amp;quot; message. I have based this off of CLI example of nRF SDK for Thread/Zigbee 4.1.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Let me know if you have questions.. though this is a learning curve for me too. &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;const char buf[10] = &amp;quot;Hello\0&amp;quot;;
static bool volatile button0_pushed;


/**@brief Function for handling bsp events.
 */
void bsp_evt_handler(bsp_event_t evt)
{
    uint32_t err_code = 0;
    switch (evt)
    {
        case BSP_EVENT_KEY_0:
            NRF_LOG_INFO(&amp;quot;BSP_EVENT_KEY_0!&amp;quot;);
            button0_pushed = true;
            break;

        case BSP_EVENT_KEY_1:
            NRF_LOG_INFO(&amp;quot;BSP_EVENT_KEY_1!&amp;quot;);
            break;

        default:
            return; // no implementation needed
    }
    APP_ERROR_CHECK(err_code);
}

static void port_data_callback(void                * p_context,
                               otMessage           * p_message,
                               const otMessageInfo * p_message_info)
{
    NRF_LOG_INFO(&amp;quot;port_data_callback&amp;quot;);
    NRF_LOG_INFO(&amp;quot;ptr to msg = %08x&amp;quot;,p_message);
}

otError send_udp_command(void)
{
    otError error = OT_ERROR_NONE;

    otUdpSocket socket;
    otMessageInfo messageInfo;


    memset(&amp;amp;messageInfo, 0, sizeof(messageInfo));

    error = otUdpOpen(thread_ot_instance_get(), &amp;amp;socket, port_data_callback, NULL);
    if (error != OT_ERROR_NONE )
    {
        NRF_LOG_INFO(&amp;quot;otUdpOpen err = %u&amp;quot;, error);
        return error;
    }
    else
    {
        NRF_LOG_INFO(&amp;quot;otUdpOpen SUCCESS!&amp;quot;);
    }
    error = otIp6AddressFromString(&amp;quot;FF03::1&amp;quot;, &amp;amp;messageInfo.mPeerAddr);
    if (error != OT_ERROR_NONE )
    {
        NRF_LOG_INFO(&amp;quot;otIp6AddressFromString err = %u&amp;quot;, error);
        return error;
    }
    messageInfo.mPeerPort = (uint16_t)1994;

    otMessage *test_Message  = otUdpNewMessage(thread_ot_instance_get(), NULL);



    error = otMessageAppend(test_Message, buf, (uint16_t)strlen(buf));
    if (error != OT_ERROR_NONE )
    {
        NRF_LOG_INFO(&amp;quot;otMessageAppend err = %u&amp;quot;, error);
        return error;
    }

    error = otUdpSend(&amp;amp;socket, test_Message, &amp;amp;messageInfo);
    if(error != OT_ERROR_NONE)
    {
        NRF_LOG_ERROR(&amp;quot;otUdpSend err = %u&amp;quot;,error);
        NRF_LOG_INFO(otThreadErrorToString(error));
        return error;
    }

     if(test_Message != NULL)
    {
        //otMessageFree(test_Message);
        NRF_LOG_INFO(&amp;quot;otMessageFree, to be added&amp;quot;);
    }


    return error;
}




/***************************************************************************************************
 * @section Main
 **************************************************************************************************/

int main(int argc, char *argv[])
{
    log_init();
    scheduler_init();
    timer_init();
    leds_init();
    otError error = OT_ERROR_NONE;

    uint32_t err_code = bsp_init(BSP_INIT_LEDS|BSP_INIT_BUTTONS, bsp_evt_handler);

    APP_ERROR_CHECK(err_code);

    while (true)
    {
        thread_instance_init();
        error = otIp6SetEnabled(thread_ot_instance_get(), true);
        if( error ){
            NRF_LOG_ERROR(&amp;quot;otIp6SetEnabled = %u&amp;quot;, error);
        }
        error = otThreadSetEnabled(thread_ot_instance_get(), true);
        if( error )
        {
            NRF_LOG_ERROR(&amp;quot;otThreadSetEnabled = %u&amp;quot;, error);
        }
        //nrf_mem_init();

        while (!thread_soft_reset_was_requested())
        {
            if( button0_pushed )
            {
                NRF_LOG_INFO(&amp;quot;btn0&amp;quot;);
                send_udp_command();
                button0_pushed = false;
            }
            thread_process();
            app_sched_execute();

            if (NRF_LOG_PROCESS() == false)
            {
                thread_sleep();
            }
        }

        thread_instance_finalize();
    }
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF hangs when sending second UDP package using thread</title><link>https://devzone.nordicsemi.com/thread/261368?ContentTypeID=1</link><pubDate>Thu, 23 Jul 2020 12:58:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d67454b-9002-48a6-9245-2ec92277df2f</guid><dc:creator>hubert_11</dc:creator><description>&lt;p&gt;Anybody? Still stuck on this.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>