need your suggestion..

i'm having a hard time figuring out how to make my gsm accepts only 3 mobile numbers for it to be commanded..
my previous work was the gsm to accept only 1 mobile number.. here's my code..

#include <FrequencyTimer2.h>
#include <SD.h>
#include<stdlib.h>

#define SD_CS 4
#define RELAY 5
#define GSM_POWER 6
#define GSM Serial
#define LED 14
#define analyzer Serial1

static String cpNum = "09XX-XXXX-XXX";
unsigned long uptime = 0;
boolean stat;
 
String aData;
String resp;
char msgLog[100];
char buffer[13];

 
 
//Called once on start of Arduino
void setup() {
  pinMode(LED, OUTPUT);
  SD.begin(SD_CS);
  analyzer.begin(9600);
  pinMode(RELAY, OUTPUT);
  FrequencyTimer2::setPeriod(16000);
  GSM.begin(9600);
  pinMode(GSM_POWER, OUTPUT);
  digitalWrite(GSM_POWER, LOW);
  delay(1500);
  digitalWrite(GSM_POWER, HIGH);
  delay(2000);
  while (readCmd() != "Call Ready");  
  GSM.println("ATE0");
  while (readCmd() != "OK");
  digitalWrite(LED, HIGH);
}

 


void powerOn() { 
  
  digitalWrite(RELAY, HIGH); 
  strcpy(msgLog, "POWER ON");
  writeToFile();
  FrequencyTimer2::setOnOverflow(incUptime);   

 
}


void getData() {
  int commaLoc[7];//response from 
  
  commaLoc[0] = aData.indexOf(',');
  for (byte i = 1; i < 7; i++) {
    commaLoc[i] = aData.indexOf(',', commaLoc[i - 1] + 1);
  }
   
}

  
 

 
void powerOff() {
  int i = 0;
  
  digitalWrite(RELAY, LOW);
  strcpy(msgLog, "POWER OFF ");
  while (msgLog[i] != '\0') {i++;}
   
  strcat(msgLog, buffer);
  stat = 0;
  
  FrequencyTimer2::setOnOverflow(0);
  writeToFile();
  while(analyzer.available()) {
    analyzer.read();
  }
}


void incUptime() {
  static byte cnt = 0;
  
  if (++cnt == 125) {
    cnt = 0;
    ++uptime;
  }
}

 
String getUptime() {
  unsigned long hr = uptime / 3600;
   
 
}

 
String leftPad(unsigned long num) {
  String str = String(num);
  
  if (num < 10) {
    str = "0" + str;
  }
  return str;
}

 
boolean sendSMS(String num, String msg) {
  GSM.print("AT+CMGS=\"");//AT command for sending message
  GSM.print(num);
  GSM.println("\"");
  while(GSM.read() != '>');//'>'
  GSM.print(msg);
  GSM.write(26);
  while(1) {
    String inpt = readCmd();
    if (inpt.startsWith("+CMGS")) {
      while (readCmd() != "OK");
      return 1;
    }
    else if (inpt.startsWith("+CMS") || inpt.startsWith("ERROR")) {
      return 0;
    }  
  }
}


void writeToFile() {
  File dataFile = SD.open("datalog.txt", FILE_WRITE);

  if (dataFile) {
    dataFile.println(msgLog);
    dataFile.close();
  }  
}

String readCmd() {
  String cmd = "";
  char tmp;
  
  while (1) {
    if ((tmp = GSM.read ()) != -1) {
      if (tmp == 10) {
        if ((cmd.length () > 1 || !cmd.startsWith ("+CMTI")) && 

cmd.endsWith ("\r")) {
          return cmd.substring (0, cmd.length () - 1);
        } else {
          cmd = "";
        }
      } else {
        cmd += tmp;
      }
    }
  }
}


String readSMS () {
  String msg = "", inpt = "";
  boolean msgRead = false;
  
  byte comma[3];
  byte i;
  
  GSM.println("AT+CMGL=\"REC UNREAD\",1");
  while ((inpt = readCmd()) != "OK") {
    if (!msgRead && inpt.startsWith("+CMGL")) {
      msgRead = true;
       
      for (i = 1; i < 3; i++) {
        comma[i] = inpt.indexOf(',', comma[i - 1] + 1);
      }
     
      msg = inpt.substring(comma[1] + 2, comma[2] - 1);
      if (msg.startsWith("+63")) {
        msg = "0" + msg.substring(3);
      }
      msg += ',';
      char temp;
      while ((temp = GSM.read()) != '\r') {
        if (temp != -1) {
          msg += temp;
        }
      }
    }
  }
  if (msgRead) {
    GSM.print("AT+CMGD=");
     
    GSM.println (",0");
    while (readCmd() != "OK");
  }
  return msg;
}


void checkMessages() {
  String msg = readSMS();

  if (msg.startsWith (cpNum)) {
    respond(msg.substring (msg.indexOf (',') + 1));
  }
}


void respond (String cmd) {  
  if (cmd == "STATUS") {
    if (stat) {
      resp = "Power is ON.\n";
      resp = resp + "Uptime: " + getUptime();
     
    } else {
      resp = "Power is OFF.";
    }
  } else if (cmd == "POWER ON") {
    if (stat) {
      resp = "Power is already ON.";
    } else {
      powerOn();
      resp = "Power ON successful";
    }
  } else if (cmd == "POWER OFF") {
    if (!stat) {
      resp = "Power is already OFF.";
    } else {
      powerOff();
      resp = "Power OFF successful. " + getUptime();
    }
  } else {
    resp = "Invalid Command.";
  }
  sendSMS(cpNum, resp);
}

Is there any special command for this matter? thank you in advance!..

How to use this forum

#7 particularly.

Arrch:
How to use this forum

#7 particularly.

done bro..

Start by taking your single String:

static String cpNum = "09XX-XXXX-XXX";

and convert it to an array containing all 3 of the numbers Then when you are comparing the number with the number of the sent message:

  if (msg.startsWith (cpNum)) {
    respond(msg.substring (msg.indexOf (',') + 1));
  }

use a for loop, and loop through all of the 3 elements in the array

Arrch:
Start by taking your single String:

static String cpNum = "09XX-XXXX-XXX";

and convert it to an array containing all 3 of the numbers Then when you are comparing the number with the number of the sent message:

  if (msg.startsWith (cpNum)) {

respond(msg.substring (msg.indexOf (',') + 1));
 }



use a for loop, and loop through all of the 3 elements in the array

this may sound stupid but just to be safe.. is this code also acceptable without affecting the other codes or future codes to be encoded? thank you!

static String cpNum = "09XX-XXXX-XXX";
static String cpNum1 = "09YY-YYYY-YYY";

then

if (msg.startsWith (cpNum)) {
    respond(msg.substring (msg.indexOf (',') + 1));
    
  }
   else if (msg.startsWith (cpNum1)){
      respond(msg.substring (msg.indexOf (',') + 1));
   }
   else 
   {
    resp = "Invalid Number!.";
  }