Go Down

Topic: how to compare incoming number and a list of predefined numbers (Read 4054 times) previous topic - next topic

ArtGan

Hi ArduPeople  :)

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!



dannable

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.

Quote
but the Ide say "error conversion "char" to "const char"
Show your code?
Beginners guide to using the Seeedstudio SIM900 GPRS/GSM Shield

nikhiljoji

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 :) all d best

vpsrprathap

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

antonio1

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


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,"<alphaId>",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=<alphaId> (which should take maximum 3s + the time to parse)…


Code: [Select]

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");



Anirban100297

I use want to see phone number from gsm shield sim card in 20*4 LCD display.. & with the help of 4*4 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  :( .. Plzz help me if possible.. Code plzz...

Go Up