cancel
Showing results for 
Search instead for 
Did you mean: 

Receiving Messages from Sim800

Ala
Senior

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 main()

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

and this part is in while()

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[i] 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]!

any help guys?

0 REPLIES 0