<?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 UART app receive value sent from uart app</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/16960/nrf-uart-app-receive-value-sent-from-uart-app</link><description>Hi, I am using the nrf uart app to communicate with a smart phone and the NRF52. I am trying to detect whenever it is sent a value between 0 and 60 from the phone, and save it to an int.
I know that I get a callback from the function nus_data_handler</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 10 Oct 2016 11:25:19 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/16960/nrf-uart-app-receive-value-sent-from-uart-app" /><item><title>RE: nrf UART app receive value sent from uart app</title><link>https://devzone.nordicsemi.com/thread/65060?ContentTypeID=1</link><pubDate>Mon, 10 Oct 2016 11:25:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:41cc4ff5-c11e-446e-a8f9-8065800edb5d</guid><dc:creator>Erblin</dc:creator><description>&lt;p&gt;Thank you for answering, my code is now working :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf UART app receive value sent from uart app</title><link>https://devzone.nordicsemi.com/thread/65057?ContentTypeID=1</link><pubDate>Mon, 10 Oct 2016 11:08:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6594a19b-230d-441b-92a3-94ccd122fe95</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;uart_event_handle(..) is used to send data to the phone, while nus_data_handler(..) is used to receive data sent from the phone.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf UART app receive value sent from uart app</title><link>https://devzone.nordicsemi.com/thread/65059?ContentTypeID=1</link><pubDate>Mon, 10 Oct 2016 11:00:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9e7ff594-1e41-4479-b689-8334cfa9eaf5</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;One solution to store the number sent from the phone, could be something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length)
{
    uint32_t myNumber = 0;
    for (uint32_t i = 0; i &amp;lt; length; i++)
    {
        while (app_uart_put(p_data[i]) != NRF_SUCCESS);
        myNumber = myNumber + ((p_data[i]-&amp;#39;0&amp;#39;)*pow(10,length-i-1));
    }
    while (app_uart_put(&amp;#39;\r&amp;#39;) != NRF_SUCCESS);
    while (app_uart_put(&amp;#39;\n&amp;#39;) != NRF_SUCCESS);
    printf(&amp;quot;myNumber is: %d\n&amp;quot;,myNumber);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You will need to add #include &amp;quot;math.h&amp;quot; for the pow()-function.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf UART app receive value sent from uart app</title><link>https://devzone.nordicsemi.com/thread/65058?ContentTypeID=1</link><pubDate>Mon, 10 Oct 2016 10:54:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:04c84f35-b55a-4029-9bef-8db6df93b2d2</guid><dc:creator>Erblin</dc:creator><description>&lt;p&gt;void uart_event_handle(app_uart_evt_t * p_event)
{
static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
static uint8_t index = 0;
uint32_t       err_code;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;switch (p_event-&amp;gt;evt_type)
{
    case APP_UART_DATA_READY:
        UNUSED_VARIABLE(app_uart_get(&amp;amp;data_array[index]));
        index++;

        if ((data_array[index - 1] == &amp;#39;\n&amp;#39;) || (index &amp;gt;= (BLE_NUS_MAX_DATA_LEN)))
        {
						
            err_code = ble_nus_string_send(&amp;amp;m_nus, data_array, index);
            if (err_code != NRF_ERROR_INVALID_STATE)
            {
                APP_ERROR_CHECK(err_code);
           ......
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I see that this function runs through the array of characters, till it gets a new line \n or is at maximum data length. How am i able to check if this array of characters contains a number between 0 and 60, and then save it to a type int?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>