SMS: Only allow specific (phone number/recipient) to receive or read

Hi guys, so I’m trying to make a program where only specific number (for example: +63123) can only make the codes or command works. However, my program here can accept any numbers (which is not suppose to do) and can send the notification the 1 recipient which is okay. Please help how to code this, I’m pretty noob and I don’t really know what to edit or where to look.

What I mean is when a random number sent “ON” or “OFF” or “STATUS” the program must not accept it and do nothing, but when +63123 sent the command, it will work. Please please help and thank you so much in advance. Any comment, suggestions and opinions are appreciated.

#include <SoftwareSerial.h>

SoftwareSerial GPRS(10, 11);

String textMessage;
String lampState;

const int relay = 12;

void setup() {  
  pinMode(relay, OUTPUT);
  digitalWrite(relay, HIGH);
  
  Serial.begin(9600); 
  GPRS.begin(9600);
  delay(5000);
  Serial.print("GPRS ready...\r\n");
  GPRS.print("AT+CMGF=1\r\n"); 
  delay(1000);
  GPRS.print("AT+CNMI=2,2,0,0,0\r\n");
  delay(1000);
}

void loop(){
  if(GPRS.available()>0){
    textMessage = GPRS.readString();
    Serial.print(textMessage);    
    delay(10);
  } 
  if(textMessage.indexOf("ON")>=0){
    // Turn on relay and save current state
    digitalWrite(relay, HIGH);
    lampState = "ON";
    Serial.println("Lamp set to ON\r\n");  
    textMessage = "";
    GPRS.println("AT+CMGS=\"+63xxxxxxxxxx\"");
    delay(500);
    GPRS.print("Lamp was finally switched ON.\r");
    GPRS.write( 0x1a );
    delay(1000);
  }
  if(textMessage.indexOf("OFF")>=0){
    // Turn off relay and save current state
    digitalWrite(relay, LOW);
    lampState = "OFF"; 
    Serial.println("Lamp set to OFF\r\n");
    textMessage = "";
    GPRS.println("AT+CMGS=\"+63xxxxxxxxxx\"");
    delay(500);
    GPRS.print("Lamp was finally switched OFF.\r");
    GPRS.write( 0x1a );
    delay(1000);
  }
  if(textMessage.indexOf("STATUS")>=0){
    String message = "Lamp is " + lampState;
    GPRS.print("AT+CMGF=1"); 
    delay(1000);
    Serial.println("Lamp state resquest");
    textMessage = "";
    GPRS.println("AT+CMGS=\"+63xxxxxxxxxx\"");
    delay(500);
    GPRS.print("Lamp is currently ");
    GPRS.println(lampState ? "ON" : "OFF");
    GPRS.write( 0x1a );
    delay(1000);
  }
}

However, my program here can accept any numbers

That doesn't make sense, as the program does nothing with numbers. Do you mean "my program can accept messages FROM any (phone) number"?

If you, why are you not getting/checking the (phone) number that the message is from? There IS a method to get the (phone) number that the message is from.

PaulS: That doesn't make sense, as the program does nothing with numbers. Do you mean "my program can accept messages FROM any (phone) number"?

If you, why are you not getting/checking the (phone) number that the message is from? There IS a method to get the (phone) number that the message is from.

Can you please share what's the method for getting the value of the sender's phone number? I'm thinking of creating a logic where "If phonenumber is = +63123 then read message .... else don't read the message" but wasn't able to do on code. :(

I thought you were using a library to communicate with the device. There are libraries for most GPRS chips that make it easy to send and receive calls and text messages. They know how to get the text message sender's phone number, so there must be some AT command to do that. Not that I know what it is...

You should not not read the text message. You should read it, and ignore it. Otherwise, it stays in the queue.

I still hope someone can help me with the codes tho.