Receiving Messages from Sim800

Hi everyone

I'm working with Sim800 which is a module for many applications such as in my case, sending and receiving SMSs. in my code, I send a certain text to Sim800 in SMS form and then I send an AT command to read it. now I want to analyze this received message. I've stored the received messages in a 250elements array called

char Rcv[250];

this is the code in which I analyze my Rcv[]

this part is declared in my code before setup()

char Rcv[250], USERS[10][13];
char CODENUMBER[36]="06A9062F0020063406450627063106470020";   
int inc=0,click=0;

and this part is in loop()

for(int i=0;i<250;i++)
{
if(Rcv[i]=='0' && Rcv[i+1]=='6' && Rcv[i+2]=='A' && Rcv[i+3]=='9' && Rcv[i+4]=='0' && Rcv[i+5]=='6' && Rcv[i+6]=='2' && Rcv[i+7]=='F' && Rcv[i+12]=='0' && Rcv[i+13]=='6' && Rcv[i+14]=='3' && Rcv[i+15]=='4'  && click==0)   //Check if "CODE SH" is sent    
			{    				
				  click=1;
				  TextMode();			
				  DeleteSMS();
				  HAL_Delay(2000);
					for(int i=0;i<250;i++)
					{
						while(Rcv[i]==CODENUMBER[inc] && inc<36)
						{
								inc++;
								if(inc==36)
								{   
										for(int j=0;j<10;j++)
										{
												if(USERS[j][0]=='\0')
												{
														HAL_Delay(1000);
														for(int n=0;n<12;n++)
														{		
																USERS[j][0]='+';	
																USERS[j][n+1]=Rcv[i+8+4*n];  
														}
														
														HAL_Delay(1000);
														AddPrompt(USERS[j]);
														HAL_Delay(3000);
														j=10;
														ClearRcv(); // to set each element of Rcv[]='\0'
														i=250;
														inc=0;
												}
										}
								
								ClearRcv(); // to set each element of Rcv[]='\0'								
								}	
						
						}	
						}
click=0;			
}
}
}

so I first check if I got the CODENUMBER text(which is a unicode message) right, and then I check if the USERS[10][13] array has any empty row to fill it with certain "char"s that I search within Rcv[] .

the problem is that even though I clear Rcv[] each time, next time it wouldn't be filled from it's 0th element! and I can see my message is started some where in the middle or at the end of Rcv[]! and rest of it is placed from 0th element! I don't know why this happens and this makes it impossible to analyse the message since I should receive CODENUMBER in a way that Rcv and Rcv[i+1] ect. are continuously after each other and not in a way that one of them is placed at the bottom of Rcv[](say Rcv[250]) and the next one is placed in Rcv[0]!

could you post the whole code in particular ClearRcv(); and the receiver code?

dear horace

Thanks for your reply.

of course! here is the code for reading the SMS. I send the proper AT Command which is "AT+CMGS=1"

HAL_UART_Receive_DMA(&huart2,(unsigned char *)Rcv,250); //for receiving the whole message

and this is for sending AT Command

void ReceiveSMS(char *Rcv){
                             //   Receive SMS
 for(int i=0; i<250; i++)
	{
	  if(Rcv[i]=='+' && Rcv[i+1]=='C' && Rcv[i+2]=='M' && Rcv[i+3]=='T' && Rcv[i+4]=='I')
		{
		 //HAL_UART_Receive_DMA(&huart2,(unsigned char *)Rcv,1);
		 HAL_UART_Transmit(&huart2,(unsigned char *)("AT+CMGR=1\n\r"),11,10);
		 Rcv[i]='X';
     i=250;		
    }
  }
}

GUYZ! I know this code is for ARM and not Arduino :sob: but I've always received big help from this community and I know the problem is not about the syntax. the problem is within the Rcv[] analyzing code.

So please hep me somehow :slightly_smiling_face: