<?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>How to compare the received data over able to the specific value...</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/81781/how-to-compare-the-received-data-over-able-to-the-specific-value</link><description>Dear team, 
 1. I am using the Ble_app_uart example from the SDK. 
 2. I had received the data successfully from the nrf_connect app. 
 3. Once the data was received over a ble after that I want to compare that data with string &amp;amp; want to perform an action</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 22 Nov 2021 10:10:17 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/81781/how-to-compare-the-received-data-over-able-to-the-specific-value" /><item><title>RE: How to compare the received data over able to the specific value...</title><link>https://devzone.nordicsemi.com/thread/339998?ContentTypeID=1</link><pubDate>Mon, 22 Nov 2021 10:10:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cbcac45f-be44-4661-af5a-93e2884e2b1f</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello ShubMane,&lt;br /&gt;&lt;br /&gt;The forum is not staffed during the weekend.&lt;/p&gt;
[quote user="ShubMane"]Thanks for the help.[/quote]
&lt;p&gt;No problem, I am happy to help!&lt;/p&gt;
[quote user="ShubMane"]&lt;p&gt;every single time I am sending the new data from NRF connect app.&lt;/p&gt;
&lt;p&gt;So Could u please tell me&lt;/p&gt;
&lt;p&gt;And I want to wait till the new data not had arrived.&lt;/p&gt;
&lt;p&gt;and once that data had arrived I want to out of that loop.&lt;/p&gt;[/quote]
&lt;p&gt;I am not certain that I understand what you mean by this. You could like to wait until the new data is received? The BLE_NUS_EVT_RX_DATA event will be generated following the successful reception of a notification or write from the peer.&lt;br /&gt;You do not have to actively wait for this transfer, since the event interrupts your program.&lt;br /&gt;&lt;br /&gt;If you wish to wait with the connection until a certain requirement is fulfilled you may instead implement a function that sets a boolean variable that you could use as a conditional for starting advertising or scanning on either side of the link.&lt;br /&gt;I.e do not start advertising or scanning until your requirement is met.&lt;br /&gt;&lt;br /&gt;Keep in mind that I do not know anything about the product you are developing, but in general the security architecture you outline below might not be the most secure, since one could just brute force it by resetting the device repeatedly.&lt;br /&gt;This might not be an issue for the product you are making, but I thought I should mention it just in case.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to compare the received data over able to the specific value...</title><link>https://devzone.nordicsemi.com/thread/339972?ContentTypeID=1</link><pubDate>Mon, 22 Nov 2021 09:02:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:84cec691-0e04-4b94-9b56-090544648484</guid><dc:creator>ShubMane</dc:creator><description>&lt;p&gt;Dear team,&lt;/p&gt;
&lt;p&gt;Please update.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to compare the received data over able to the specific value...</title><link>https://devzone.nordicsemi.com/thread/339940?ContentTypeID=1</link><pubDate>Mon, 22 Nov 2021 05:18:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e0088ffa-1dd5-432e-93af-01cc5192ceaf</guid><dc:creator>ShubMane</dc:creator><description>&lt;p&gt;Dear team,&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Please update on priority..&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to compare the received data over able to the specific value...</title><link>https://devzone.nordicsemi.com/thread/339916?ContentTypeID=1</link><pubDate>Sat, 20 Nov 2021 11:58:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c09da8a5-943d-4e9c-8ce3-cd0eac041fea</guid><dc:creator>ShubMane</dc:creator><description>&lt;p&gt;hi Karl,&lt;/p&gt;
&lt;p&gt;I want to implement the logic as below in the normal c code in nus data handler.&lt;/p&gt;
&lt;p&gt;scanf provides the wait state till the user puts the data.&lt;/p&gt;
&lt;p&gt;in the same way, I want to put the wait state till the nrf_connect app sends the data to slave (nus_data_handler).&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;string.h&amp;gt;

int main()
{
	char password[6];
	
	// 1st attempt
	printf(&amp;quot;\nPlease enter the password : &amp;quot;);
	scanf(&amp;quot;%s&amp;quot;,&amp;amp;password); // wait state 
	
	
	if(strcmp(password, &amp;quot;123456&amp;quot;) == 0)
	{
		printf(&amp;quot;\nPassword is correct&amp;quot;);
	}
	
	if(strcmp(password, &amp;quot;123456&amp;quot;) != 0)
	{	// 2nd attempt
		printf(&amp;quot;\nPassword is not correct!!! please try again&amp;quot;);
		printf(&amp;quot;\nPlease enter the password : &amp;quot;);
		scanf(&amp;quot;%s&amp;quot;,&amp;amp;password); // wait state 
		
		
		if(strcmp(password, &amp;quot;123456&amp;quot;) == 0)
		{
			printf(&amp;quot;\nPassword is correct&amp;quot;);
		}
		
		if(strcmp(password, &amp;quot;123456&amp;quot;) != 0)
		{
			// 3rd attempt
			printf(&amp;quot;\nPassword is not correct!!! please try again&amp;quot;);
			printf(&amp;quot;\nPlease enter the password : &amp;quot;);
			scanf(&amp;quot;%s&amp;quot;,&amp;amp;password); // wait state
			
			if(strcmp(password, &amp;quot;123456&amp;quot;) == 0)
			{
				printf(&amp;quot;\nPassword is correct&amp;quot;);
			}
			
			if(strcmp(password, &amp;quot;123456&amp;quot;) != 0)
			{
				printf(&amp;quot;\nYour all attempt had finished!! Please reset device&amp;quot;);
			}
			
		}
	}
	return 0;
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to compare the received data over able to the specific value...</title><link>https://devzone.nordicsemi.com/thread/339908?ContentTypeID=1</link><pubDate>Sat, 20 Nov 2021 11:12:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3967db91-cbb0-42c5-b622-eb53348e599a</guid><dc:creator>ShubMane</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void nus_data_handler(ble_nus_evt_t * p_evt)
{
    int attempt = 0;
    char arr[6];
    char arr_1[6];
    
    bool flag = 0;
    
    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_evt-&amp;gt;params.rx_data.p_data, p_evt-&amp;gt;params.rx_data.length);

        for (uint32_t i = 0; i &amp;lt; p_evt-&amp;gt;params.rx_data.length; i++)
        {
            do
            {
                err_code = app_uart_put(p_evt-&amp;gt;params.rx_data.p_data[i]);

                if ((err_code != NRF_SUCCESS) &amp;amp;&amp;amp; (err_code != NRF_ERROR_BUSY))
                {
                    NRF_LOG_ERROR(&amp;quot;Failed receiving NUS message. Error 0x%x. &amp;quot;, err_code);
                    APP_ERROR_CHECK(err_code);
                }
            }while (err_code == NRF_ERROR_BUSY);
        }
        if(p_evt-&amp;gt;params.rx_data.p_data[p_evt-&amp;gt;params.rx_data.length - 1] == &amp;#39;\r&amp;#39;)
        {
            while (app_uart_put(&amp;#39;\n&amp;#39;) == NRF_ERROR_BUSY);
        }

        //storing the data into array which is comming from the ble_master(nrf_connect app)
        for(int i=0; i&amp;lt;=5; i++)
        {
          arr[i] = p_evt-&amp;gt;params.rx_data.p_data[i];
        }

        if(strcmp(arr, &amp;quot;123456&amp;quot;) == 0)
        {
          printf(&amp;quot;\nPassword is correct&amp;quot;);
        }

        if(strcmp(arr, &amp;quot;123456&amp;quot;) != 0)
        {
          printf(&amp;quot;\nPassword is incorrect!!! Please try again&amp;quot;);
          printf(&amp;quot;\nPassword : &amp;quot;); // after this I want to wait till the new data had arrived.

          //strcpy(arr_1, arr);

          if(strcmp(arr, &amp;quot;123456&amp;quot;) == 0)
          {
            printf(&amp;quot;\nPassword is correct&amp;quot;);            
          }

        }    
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to compare the received data over able to the specific value...</title><link>https://devzone.nordicsemi.com/thread/339907?ContentTypeID=1</link><pubDate>Sat, 20 Nov 2021 11:10:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d23537a0-6e7e-4482-8ceb-54afac092b50</guid><dc:creator>ShubMane</dc:creator><description>&lt;p&gt;How to wait till the new data had come from NRF connect app.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to compare the received data over able to the specific value...</title><link>https://devzone.nordicsemi.com/thread/339906?ContentTypeID=1</link><pubDate>Sat, 20 Nov 2021 10:28:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ff7b9ca1-bee7-4f3c-99b2-441e40ec2094</guid><dc:creator>ShubMane</dc:creator><description>&lt;p&gt;Hi Karl,&lt;/p&gt;
&lt;p&gt;Thanks for the help.&lt;/p&gt;
&lt;p&gt;every single time I am sending the new data from NRF connect app.&lt;/p&gt;
&lt;p&gt;So Could u please tell me&lt;/p&gt;
&lt;p&gt;And I want to wait till the new data not had arrived.&lt;/p&gt;
&lt;p&gt;and once that data had arrived I want to out of that loop.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to compare the received data over able to the specific value...</title><link>https://devzone.nordicsemi.com/thread/339905?ContentTypeID=1</link><pubDate>Sat, 20 Nov 2021 10:11:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:37edcb43-db70-41da-88b6-958c78af1495</guid><dc:creator>ShubMane</dc:creator><description>&lt;p&gt;Hi Karl,&lt;/p&gt;
&lt;p&gt;Thanks for the help.&lt;/p&gt;
&lt;p&gt;every single time I am sending the new data from NRF connect app.&lt;/p&gt;
&lt;p&gt;So Could u please tell me&lt;/p&gt;
&lt;p&gt;And I want to wait till the new data had arrived&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to compare the received data over able to the specific value...</title><link>https://devzone.nordicsemi.com/thread/339363?ContentTypeID=1</link><pubDate>Wed, 17 Nov 2021 09:22:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d47b499d-e8f1-4117-8ae3-4f99dbb7844e</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Yes, you may do so in the BLE_NUS_EVT_RX_DATA event that I mentioned in my previous comment.&lt;br /&gt;The data is retrieved byte-for-byte in the following section of the event handler:&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;..
        for (uint32_t i = 0; i &amp;lt; p_evt-&amp;gt;params.rx_data.length; i++)
        {
            do
            {
                err_code = app_uart_put(p_evt-&amp;gt;params.rx_data.p_data[i]);
                if ((err_code != NRF_SUCCESS) &amp;amp;&amp;amp; (err_code != NRF_ERROR_BUSY))
                {
                    NRF_LOG_ERROR(&amp;quot;Failed receiving NUS message. Error 0x%x. &amp;quot;, err_code);
                    APP_ERROR_CHECK(err_code);
                }
            } while (err_code == NRF_ERROR_BUSY);
        }
..&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You may remove the app_uart_put call if you do not wish for it to be sent to the UART peripheral, and then instead read the p_evt-&amp;gt;params.rx_data.p_data into another variable for later processing.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to compare the received data over able to the specific value...</title><link>https://devzone.nordicsemi.com/thread/339327?ContentTypeID=1</link><pubDate>Wed, 17 Nov 2021 04:35:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:648f3b44-2dca-4a12-ad93-ed1fec00e074</guid><dc:creator>ShubMane</dc:creator><description>&lt;p&gt;Respected Karl,&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Please update&lt;/p&gt;
&lt;p&gt;I just want to store the data which is coming from the nrf_connect app(master) to the slave (PCA10040)&lt;/p&gt;
&lt;p&gt;as well as it&amp;#39;s going printed on the terminal (putty).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;for example, if I am sending the data &amp;quot;123456&amp;quot; from nrf connect app that data i want to store into the variable&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to compare the received data over able to the specific value...</title><link>https://devzone.nordicsemi.com/thread/339237?ContentTypeID=1</link><pubDate>Tue, 16 Nov 2021 13:25:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5e55b7ab-cb8d-460e-a596-8ec0b91e576e</guid><dc:creator>ShubMane</dc:creator><description>&lt;p&gt;So once the data is stored in the variable so I can perform the action accordingly.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to compare the received data over able to the specific value...</title><link>https://devzone.nordicsemi.com/thread/339236?ContentTypeID=1</link><pubDate>Tue, 16 Nov 2021 13:24:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8d3cf8cf-d77d-4626-a4d7-ae4f9c0d8433</guid><dc:creator>ShubMane</dc:creator><description>&lt;p&gt;Hi Karl,&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;I just want to store the received data into the variable which is coming from the nrf_connect app&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to compare the received data over able to the specific value...</title><link>https://devzone.nordicsemi.com/thread/339227?ContentTypeID=1</link><pubDate>Tue, 16 Nov 2021 13:01:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:34087731-e627-4442-abe0-2ca6bc266a28</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;br /&gt;&lt;br /&gt;The standard behavior of the example is just to forward any data received over the NUS service to the UART peripheral. This happens as part of the BLE_NUS_EVT_RX_DATA event handling in the&amp;nbsp;&lt;em&gt;nus_data_handler&amp;nbsp;&lt;/em&gt;function. If you wish to modify the example to do something else with this data, or check it for some special sequence, you could implement this as part of the BLE_NUS_EVT_RX_DATA event as well / instead of the existing functionality.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>