Help to check a phone number on Sim800L in SMS Calls sketch

Hi to every one,

In this sketch also i create an IF statement for CLIP to check if is admin or authorized phone.

In can't (don't know) how to check in an SMS if number is from an authorized person.

My extension from that sketch i have done the following: check if is an admin or authorized number from a SD file , to LOG who is calling also in SD.

Also i wish to know how to implement in LOG file date time from GSM network with PSUTTZ.
And final , how to add a break also in void timer () . For ex: TIMER5 (open gate for 5 minute) and meantime i wish to send OFF sms to cancel it.
When is in TIMER loop, all sketch is ,,frozen" in delay(xxxx) because is linear IF's ?

Edit: i try it to implement millis() , is not working.
After i send SMS with ON , led is ON but, system is not reacting to calls until is send OFF(not reacting to IF statment). Just i see on terminal Ring , CLIP info, sketch is locked in some loop?

Any help ?
Regards.

This is received SMS :

+CMT: "+40726138789","","21/01/17,18:43:30+08" (this is SMS sender)

On (this is message)

#include <SPI.h>

#include <SD.h>

#include <SoftwareSerial.h>

/*
 * SIM800L SMS RELAY v1.1 + CALLS
 * Arduino Hardware TTGO T-CAL
 * Arduino IDE (Author): 1.8.13
 * RIVELINO V1.1
 */


//#include 
SoftwareSerial mySerial(26,27);  // (Rx,Tx  > Tx,Rx) 

#define SIM800L_PWRKEY 4
#define SIM800L_RST    5
#define SIM800L_POWER  23

char incomingByte; 
String inputString;
int relay = 13; // Output for Relay Control
int RelayState = 0;
#define SECRET_ADMINNUMBER "+40726138789"
String adminphone = SECRET_ADMINNUMBER;
String callnumber = "";

//millis
unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period1 = 1000*20; //20 SEC
//const unsigned long period1 = 1000*60*1;  //1000( 1 second) * 60 (60 sec=1 minute) * 1 (1 minutes)
const unsigned long period5 = 1000*60*5;  //1000( 1 second) * 60 (60 sec=1 minute) * 5 (5 minutes)

void setup() 
{
      
      pinMode(SIM800L_POWER, OUTPUT);
      digitalWrite(SIM800L_POWER, HIGH);
      
      pinMode(relay, OUTPUT);
      digitalWrite(relay, LOW); // Initial state of the relay
      Serial.begin(115200);
      mySerial.begin(4800); 
      //millis
      startMillis = millis();  //save the start time

     while(!mySerial.available()){
        mySerial.println("AT");
        delay(1000); 
        Serial.println("Connecting...");
        }
      Serial.println("Connected!");  
      mySerial.println("AT+CMGF=1");  //Set SMS to Text Mode 
      delay(1000);  
      mySerial.println("AT+CNMI=1,2,0,0,0");  //Procedure to handle newly arrived messages(command name in text: new message indications to TE) 
      delay(1000);
      mySerial.println("AT+CMGL=\"REC UNREAD\""); // Read Unread Messages
     }

void loop()
{  
  if(mySerial.available()){
    RelayState = digitalRead(relay);
      delay(100);

      // Serial Buffer
      while(mySerial.available()){
        incomingByte = mySerial.read();
        inputString += incomingByte; 
        }

        delay(10);

              currentMillis = millis();

        Serial.println(inputString);
        inputString.toUpperCase(); // Uppercase the Received Message

       if ((inputString.indexOf("CLIP") > -1) & (RelayState == LOW)) {
      // Check for a phone number and add to the stored file
      int startindex = inputString.indexOf("\"");
      int endindex = inputString.indexOf("\",");
      //int endindex = startindex +14;
      callnumber = inputString.substring(startindex + 1, endindex);
      Serial.print(F("CALL NUMBER : ")); Serial.println(callnumber);
      Serial.println(F("HANG UP PHONE"));
      mySerial.println("ATH");
      //verificare_numere(); - Here i create a reading from SD file to check admin numbers 
      

      if (adminphone.equals(callnumber)) {
        Serial.println("Admin phone, open gate!");
        Serial.println (callnumber);
        // open the gate and after 5 second close it
        digitalWrite(relay, HIGH);
        delay(5000);
        digitalWrite(relay, LOW);
      }
      else {  Serial.println("NOT ADMIN!!!!");
        Serial.println (callnumber);
      }
          
      
      
    }
        // TIMER SMS FOR OPEN GATE
    if ((inputString.indexOf("TIMER") > -1) & (RelayState == LOW)){  
      Serial.println(F("TIMER"));
      timer();   
    } 
        
        //turn RELAY ON or OFF
        if (inputString.indexOf("ON") > -1){
          digitalWrite(relay, HIGH);
          }
         if (inputString.indexOf("OFF") > -1){
          digitalWrite(relay, LOW);
          }          

        delay(50);

        //Delete Messages & Save Memory
        if (inputString.indexOf("OK") == -1){
        mySerial.println("AT+CMGDA=\"DEL ALL\"");

        delay(1000);}

        inputString = "";
  }
}
void timer () {
  
// currentMillis = millis();
if ((inputString.indexOf("TIMER1") > -1) & (RelayState == LOW)){  
      Serial.println(F("TIMER 1 MIN"));
      Serial.println("ACTIVATE RELAY");
      digitalWrite(relay,HIGH);
      Serial.print("CURENT MILLIS :");
    Serial.println(currentMillis);
    Serial.print("START MILLIS :");
    Serial.println(startMillis);
    Serial.print("PERIOD :");
    Serial.println(period1);
      if (currentMillis - startMillis >= period1)  //true until the period elapses.  Note that this is the reverse of BWOD
       {
      void loop(); 
      Serial.println("DEACTIVATE RELAY");
      digitalWrite(relay, LOW);
      startMillis = currentMillis;  //IMPORTANT to save the start time
      //delay(5000);
       }
        
    }
 if ((inputString.indexOf("TIMER55") > -1) & (RelayState == LOW)){  
      Serial.println(F("TIMER 5 MIN"));
      if (currentMillis - startMillis <= period5)  //true until the period elapses.  Note that this is the reverse of BWOD
       {
      digitalWrite(relay, LOW);
      startMillis = currentMillis;  //IMPORTANT to save the start time
      //delay(5000);
       }
      digitalWrite(relay, HIGH);
      inputString = "";
      mySerial.flush();
      void loop();    
    }


    
/*  if ((inputString.indexOf("TIMER1") > -1) & (RelayState == LOW)){  
      Serial.println(F("TIMER 1 MIN"));
      inputString = "";
      mySerial.flush();
      void loop();
      inputString = "";
      digitalWrite(relay, HIGH);
      delay(50000);
      digitalWrite(relay, LOW);   
    }
*/    
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.