[PIC] How to compare the calling no in gsm coding for controlling the load

Status
Not open for further replies.

Logu KS

Member level 2
Joined
Jul 19, 2014
Messages
43
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Location
Chennai
Visit site
Activity points
372
I programmed for controlling a pin in my controller using a call made to the sim number connected in the quectel m10 gsm modem. I wrote the code for comparing the RING which we will get while calling. But my requirement is to control that through a particular number. When i call from a particular number the switching operation should take place. For that what i have to do.

I tried AT+CLIP=1;
which showed the dialling number in hyperterminal when the modem is connected to PC.
But I have to compare that number also so that switching of the load will take place by that number alone.
 

you have to store the number (in eeprom memory) you want to compare with incoming phone number. then you can parse the incoming number from the string that you received when receiving incoming call and compare with the already stored number.
 

my at commands for receiving call is
AT
Modem respone OK
ATE0
OK
AT+CLIP=1
OK

Now the modem is configure

if i call then the following comes in hyperterminal

RING

+CLIP: "+91XXXXXXXXXX",145,"",,"",0

in my code i wrote comparision for RING. For that o/p is coming correctly. If i call from any number i am getting output but i need output only when i call from my number.

- - - Updated - - -

i compare like this
Code:
if(msg[0]=='R'&&msg[1]=='I'&&msg[2]=='N'&&msg[3]=='G'&&msg[4]=='+'&&msg[5]=='C'&&msg[6]=='L'&&msg[7]=='I'&&msg[8]=='P'&&msg[9]==':'&&msg[10]==' '&&msg[11]=='"'&&msg[12]=='+'&&msg[13]=='9'&&msg[14]=='1'&&msg[15]=='9'&&msg[16]=='7'&&msg[17]=='8'&&msg[18]=='9'&&msg[19]=='3'&&msg[20]=='9'&&msg[21]=='3'&&msg[22]=='7'&&msg[23]=='2'&&msg[24]=='4'&&msg[25]=='"'&&msg[26]==','&&msg[27]=='1'&&msg[28]=='4'&&msg[29]=='5'&&msg[30]==','&&msg[31]=='"'&&msg[32]=='"'&&msg[33]==','&&msg[34]==','&&msg[35]=='"'&&msg[36]=='"'&&msg[37]==','&&msg[38]=='0')
	  		{
	      		RD0=0;
	      		RD1=0;
	      		for(del=0;del<30;del++)
	      		{
	    		delay(60000);
	    		}
				RD0=1;
				RD1=1;
			}

- - - Updated - - -

i compare like this
Code:
if(msg[0]=='R'&&msg[1]=='I'&&msg[2]=='N'&&msg[3]=='G'&&msg[4]=='+'&&msg[5]=='C'&&msg[6]=='L'&&msg[7]=='I'&&msg[8]=='P'&&msg[9]==':'&&msg[10]==' '&&msg[11]=='"'&&msg[12]=='+'&&msg[13]=='9'&&msg[14]=='1'&&msg[15]=='9'&&msg[16]=='7'&&msg[17]=='8'&&msg[18]=='9'&&msg[19]=='3'&&msg[20]=='9'&&msg[21]=='3'&&msg[22]=='7'&&msg[23]=='2'&&msg[24]=='4'&&msg[25]=='"'&&msg[26]==','&&msg[27]=='1'&&msg[28]=='4'&&msg[29]=='5'&&msg[30]==','&&msg[31]=='"'&&msg[32]=='"'&&msg[33]==','&&msg[34]==','&&msg[35]=='"'&&msg[36]=='"'&&msg[37]==','&&msg[38]=='0')
	  		{
	      		RD0=0;
	      		RD1=0;
	      		for(del=0;del<30;del++)
	      		{
	    		delay(60000);
	    		}
				RD0=1;
				RD1=1;
			}
i moved RCREG contents to msg[]
 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
char function(void)
{
char string[];
char number[]= "xxxxxxxxxx";
 
for(i = 0; string[i] != 0; i++)
 {
   if(string[i] == num[0])
   {
     for(j = 0; num[j]!= 0; j++)
     if(string[i + j] != num[j])
     break;
   
     if(num[j] == 0)
     return TRUE
   }
}
return FALSE
}

 

Code:
#include<pic.h>

void serial_init();
void serial_char(unsigned char);
void serial_string(unsigned char *);
void serial_get(unsigned char);
void gsm_init();
void delay(unsigned int);
unsigned char msg[40],j=0,start=0,got=0,rec;

void delay(unsigned int del)
{
	while(del--);
}

void serial_init()
{
	TXSTA=0X24;
	RCSTA=0X90;
	SPBRG=25;
}

void serial_char(unsigned char val)
{
	TXREG=val;
	while(!TXIF);
	TXIF=0;
}

void serial_string(unsigned char *string)
{
	while(*string)
	{
		serial_char(*string++);
	}
}

void gsm_init()
{
	serial_string("AT");
	serial_char(0x0d);
	serial_char(0x0a);
	delay(65000);
	delay(65000);
	serial_string("ATE0");
	serial_char(0x0d);
	serial_char(0x0a);
	delay(65000);
	delay(65000);
	serial_string("AT+CLIP=1");
	serial_char(0x0d);
	serial_char(0x0a);
	delay(65000);
	delay(65000);
//	serial_string("AT+CMGF=1");
//	serial_char(0x0d);
//	serial_char(0x0a);
//	delay(65000);
//	delay(65000);
//	serial_string("AT+CNMI=2,2,0,0,0");
//	serial_char(0x0d);
//	serial_char(0x0a);
//	delay(65000);
//	delay(65000);
//	serial_string("AT+CLIP=1");
//	serial_char(0x0d);
//	serial_char(0x0a);
//	delay(65000);
//	delay(65000);
}

void interrupt external()
{
	if(RCIF)
	{			
		rec=RCREG;
		if(start==1)
		{
			msg[j]=rec;
			j++;
			if(rec==0X0D)
			{
				got=1;
			}
		}
		if(start==0)
		{ 
            if(rec==0X0A)
			{
				start=1;
			}
		}
	RCIF=0;
	}
}

void main()
{
	unsigned char del;
	TRISD=0X00;
	PORTD=0X00;
	RD0=1;
	RD1=1;
	GIE=1; 
 	PEIE=1;           
 	INTE=1;
	RCIE=1;
 	RCIF=0;         
 	INTEDG=1;
 	serial_init();
 	delay(65000);
	delay(65000);
	gsm_init();
	
	while(1)
	{
		if(got==1)
    	{ 
        	got=0;
      		j=0;
      		start=0;

       		if(msg[0]=='R'&&msg[1]=='I'&&msg[2]=='N'&&msg[3]=='G'&&msg[4]=='+'&&msg[5]=='C'&&msg[6]=='L'&&msg[7]=='I'&&msg[8]=='P'&&msg[9]==':'&&msg[10]==' '&&msg[11]=='"'&&msg[12]=='+'&&msg[13]=='9'&&msg[14]=='1'&&msg[15]=='9'&&msg[16]=='7'&&msg[17]=='8'&&msg[18]=='9'&&msg[19]=='3'&&msg[20]=='9'&&msg[21]=='3'&&msg[22]=='7'&&msg[23]=='2'&&msg[24]=='4'&&msg[25]=='"'&&msg[26]==','&&msg[27]=='1'&&msg[28]=='4'&&msg[29]=='5'&&msg[30]==','&&msg[31]=='"'&&msg[32]=='"'&&msg[33]==','&&msg[34]==','&&msg[35]=='"'&&msg[36]=='"'&&msg[37]==','&&msg[38]=='0')
	  		{
	      		RD0=0;
	      		RD1=0;
	      		for(del=0;del<30;del++)
	      		{
	    		delay(60000);
	    		}
				RD0=1;
				RD1=1;
			}
		}
	}
}
this is my whole code in this how to compare the number.
 

1. save the desired phone number in eeprom or in a variable (as said by venkatesh).
2. when call received, start saving all characters into variable (buffer).
3. Once you received the entire string, parse the incoming phone number from the received string and store the phone number in variable
4. read the eeprom and store in variable
5. compare both phone number
6. if true, then switch on/off the device.

pmk

- - - Updated - - -

did you see that whether all the received characters are saved correctly on msg variable?

pmk

- - - Updated - - -

for simplicity,

use the string function strstr. refer the URL:

http://www.codingunit.com/c-reference-string-h-string-operation-strstr

pmk
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…