Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Receiving data from nRF UART compared to data from nRF Connect

Hello Nordic community! My setup is pca10040, android tablet, s132, sdk14.2.

This time I am trying to understand why this code:

uint8_t 		string2[40];
uint8_t			siusti_duomenis1[60];
char indentification_string[]="Hello_Simb";
static void nus_data_handler(ble_nus_evt_t * p_evt)
{
	char received_string[81], received_string2[81];

	uint8_t index_to_symbol;
	const char *pointer_to_symbol;
	char *pointer_to_received_string= received_string;

    if (p_evt->type == BLE_NUS_EVT_RX_DATA)
    {	
			received_data_length = p_evt->params.rx_data.length;
			sprintf(received_string,"%s",p_evt->params.rx_data.p_data);	
			received_string[received_data_length]='\0'; // Panaikinami praejusio seanso metu irasyti simboliai ilgesni, nei dabar gauto stringo ilgis.
			
			sprintf(received_string2,"%s",p_evt->params.rx_data.p_data);
			received_string2[received_data_length]='\0'; // Panaikinami praejusio seanso metu irasyti simboliai ilgesni, nei dabar gauto stringo ilgis.
			
			sprintf((char*)string1,"Received from phone:%s\r\n",received_string);
			SEGGER_RTT_WriteString(0, (char*)string1);
			
			
			if(identification_flag == false)
		{
			if( strcmp(received_string,indentification_string) == 0)
			{
				identification_flag = true;
				SEGGER_RTT_WriteString(0,"Identification succedded\n\r");
				sprintf((char*)string2,"Identification succedded\n\r");
				sprintf((char*)siusti_duomenis1,"H:%.2f T:%.2f BATTERY:%d BAT_V:%.2f MYGT:%d",BME280_humidity,BME280_temperature,BAT_PERCENT,BAT_VOLT,mygtukas_nuspaustas);
				ble_nus_string_send(&m_nus,string2,&ilgis_40);
				ble_nus_string_send(&m_nus,siusti_duomenis1,&ilgis_60);
				string2[0] = '\0';
				siusti_duomenis1[0]='\0';
			}
			else
			{
				SEGGER_RTT_WriteString(0,"Identification failed\n\r");
				sprintf((char*)string2,"Identification failed\n\r");
				ble_nus_string_send(&m_nus,string2,&ilgis_40);
				string2[0] = '\0';
			}
		}

While using nrf toolbox nrf UART prints out in RTT viewer "identifiaction failed" message and while using nrf Connect application, i receive "Identification succedded" message? Hoewer I am sending the same: "Hello_simb" string which should be recognised.

If there is lack of data, please, let me know.

Best regards 

Parents Reply
  • Hi 

    I had to declare some variables to make your code compile, but I was able to figure it out. 

    Strangely enough I don't have any issues using nRF Toolbox. After I added your "Hello_Simb" string I get the "identification succeeded" message in return. 

    Can you try to use the debugger, and set a break point inside the if (p_evt->type == BLE_NUS_EVT_RX_DATA) section?

    Then you can have a look at the length of the data and the content, and see if it matches the id string. In my case the length is 10 as expected, and the data seems to match. 

    Best regards
    Torbjørn

Children
Related