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