how to compare incoming number and a list of predefined numbers

Hi ArduPeople :slight_smile:

I am trying to compare the incoming call number with a predefined number,
I get it, but now I want to add more predefined numbers is this possible?
The Idea is that the Arduino do something only with authorized numbers

I Try this and work, but use to much lines

#include <SoftwareSerial.h>
char inchar; // Will hold the incoming character from the GSM shield
SoftwareSerial SIM900(7, 8);

void setup()
{
Serial.begin(19200);
// set up the digital pins to control
pinMode(13, OUTPUT); // se define el Pin13 como una salida
digitalWrite(13, LOW); // se define el Pin13 en estado bajo

// wake up the GSM shield
SIM900power();
SIM900.begin(19200);
delay(2000); // give time to log on to network.
SIM900.print("AT+CLIP=1\r"); // turn on caller ID notification
delay(100);
}

void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
digitalWrite(9, HIGH); // Pin9 se usara para encender modulo gsm via transistor
delay(1000);
digitalWrite(9, LOW);
delay(8000);
}

void doSomething()
{
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
Serial.println("Activando");
delay(1000);
SIM900.print("ATH\r");
}

void loop()
{
if(SIM900.available() >0)
{
delay(10);
inchar=SIM900.read();
if (inchar=='5')
{
delay(10);
inchar=SIM900.read();
if (inchar=='6')
{
delay(10);
inchar=SIM900.read();
if (inchar=='9')
{
delay(10);
inchar=SIM900.read();
if (inchar=='5')
{
delay(10);
inchar=SIM900.read();
if (inchar=='1')
{
delay(10);
inchar=SIM900.read();
if (inchar=='0')
{
delay(10);
inchar=SIM900.read();
if (inchar=='5')
{
delay(10);
inchar=SIM900.read();
if (inchar=='2')
{
delay(10);
inchar=SIM900.read();
if (inchar=='1')
{
delay(10);
inchar=SIM900.read();
if (inchar=='9')
{
delay(10);
inchar=SIM900.read();
if (inchar=='2')
{
Serial.println("Numero Autorizado");
delay(100);

doSomething(); // now the number is matched, do something
delay(1000); // arbitrary delay so the function isn't called again on the same phone call
}
}
}
}
}
}
}
}
}
}
}
}
}

I try to create an array for the predefined number and then compare, with
inchar with strcmp or strncmp, but the Ide say "error conversion "char" to "const char"
I want to do this for authorice predefined numbers and generate a log, if is possible I
want to add Date/Time in the log.

I am a new in Arduino and C.

Please help me!

Nice to see that you have read and embraced the sticky at the top of the board, 'How to use this forum', specifically the use of code tags.

The way to do it is, as you note, to use arrays and compare the CLIP number with your predefined list.

but the Ide say "error conversion "char" to "const char"

Show your code?

While receiving a call or a message through a GSM module you will get a bunch of data that includes "date" , "time","phone number" ..etc

to fetch the number from the incoming data you can use "indexof" command ..

Suppose if you have saved this number 97865xx556

and now when you got a call if want to know whether the call is coming from that number you can use the following code sample

while (Serial.available())
{
delay(3);
d = Serial.readString();
if(d.indexOf("97865xx556 ") >=0)
{
Serial.println("call is from saved number");
}

This is the logic of the program . Just give a try with this :slight_smile: all d best

K as you said we can compare that number with indexof(something),, good sir,

but can we access only that incoming number and can we store that number for later use!!!! if we do this,, we won't be having any problem for comparing with any other numbers or whatever,, we can do whatever we want,, but how to do it sir ,, can any body help???????

thank you

I'm also interested in your request, I would like to get the number and to do anything with it as a variable process.

Add the number to the SIM PhoneBook CLIP should do the work for you…

You can decide to blacklist numbers where the text of the PB entry starts with '!' or are above index 127.

Whilst receiving a call, parse the +CLIP: line eg.
RING
+CLIP: "+123444719",145,"",0,"",0

Get the alphaId part (converted as an integer):

  • if empty then caller is 404 (unknown);
  • if below 0 (signed interger) || above 127 (unsigned) then caller is 403 (blacklisted);
  • if between 1 and 127 then200 (known);

If you managing (un)authorized callers using the text part of the phonebook entries you'll then query the phonebook using AT+CPBR= (which should take maximum 3s + the time to parse)…

int i=0;
int r=0;
char* p=strstr(buffer,"+CLIP:");
p = strtok(p,",");
while(p != NULL)
{  switch(++i)
    { case 5:
          r=atoi(strtok(p,"\""));
          break;
       // 1 number, 2 type, 3 subaddress, 4 sub address type, 5 alphaId (phonebook index), 6 CLI Validity
    } 
    p = strtok(NULL,",");
}
if(r>0 && r <128)Serial.println("Known and authorized CallerID");
…

I use want to see phone number from gsm shield sim card in 204 LCD display.. & with the help of 44 keypad i want to change the sim number location address.. When m press a key the location address increase & automatically the number will be changed & when m press other key the location address increase & number will be changed automatically.. Plzz help me out.. I dont know how to solve this problem :frowning: .. Plzz help me if possible.. Code plzz...

LLANGE:
Add the number to the SIM PhoneBook CLIP should do the work for you…

You can decide to blacklist numbers where the text of the PB entry starts with '!' or are above index 127.

Whilst receiving a call, parse the +CLIP: line eg.
RING
+CLIP: "+123444719",145,"",0,"",0

Get the alphaId part (converted as an integer):

  • if empty then caller is 404 (unknown);
  • if below 0 (signed interger) || above 127 (unsigned) then caller is 403 (blacklisted);
  • if between 1 and 127 then200 (known);

If you managing (un)authorized callers using the text part of the phonebook entries you'll then query the phonebook using AT+CPBR= (which should take maximum 3s + the time to parse)…

int i=0;

int r=0;
char* p=strstr(buffer,"+CLIP:");
p = strtok(p,",");
while(p != NULL)
{  switch(++i)
    { case 5:
          r=atoi(strtok(p,"""));
          break;
      // 1 number, 2 type, 3 subaddress, 4 sub address type, 5 alphaId (phonebook index), 6 CLI Validity
    }
    p = strtok(NULL,",");
}
if(r>0 && r <128)Serial.println("Known and authorized CallerID");

I am also trying to get the number from SIM card with "AT+CPBF="Arduino"" and output like +CPBF: 1,"XXXXXXXXXXXXXX",255,"Arduino.

above you code is giving error 'buffer' was not declared in this scope.

I have the solution of this problem,

1: define a predefined number as array

code: const char number1[] = {"56988888888"};

2:create an array whith the calling phone number

code: char phone_number[11];

3: sent AT command with parameters to a function like this
code: sendATcommand("AT+CLIP=1", "OK", 2000); // ATcommand, expected_answer, timeout

4: if allready... in the loop wait for serial data incoming from a call...then filter the incomming number from the respose of the gprs module, a response has the format :

RING

+CLIP: "569XYXYXYXY",129,,,,0

the number is before "

code:

byte j = 0;
while (received[j] != '"') j++;
j++;

for (byte i = 0; i < 11; i++) // son 11 numeros a guardar en el array
{
phone_number = received[i + j];

  • }*

  • } // Fin del if answer=1*

  • for (int i = 0; i < 11; i++) {*

  • // Print phone number:*

Serial.print(phone_number*); //imprime en el puerto serial al numero de telefono de quien llama*
5: compare incoming number whith predefined number1[]
switch (compareNumber(phone_number)) {

* case 0:*
* Serial.print("Numero llamando");*
* SSerial.println("AT+CHUP"); //hang up the call*
* SSerial.flush();*
* digitalWrite(LED5, LOW); // leds for example*
* delay(1000);*
* digitalWrite(LED5, HIGH);*
* break;*
I have the full code working an functional, is somewhere is interested contactme