INTRO:
I'm a novice when it comes to Arduino programming and using AT commands. I already tried to search the whole internet and asked on Arduino forum, but I have no luck and nobody seems to give me a clear idea about it there.
PROBLEM:
So, I have this code where an SMS command can switch on and off the light and it will response to a specific phone number only. My problem is, the program response even when I'm using different phone numbers. I hope there's a way which it can only whitelist a specific number so no one can prank the program without the owner's knowledge.
FOR EXAMPLE:
- The owner's phone number is +631234567890
- Some random phone number: +63xxxxxxxxxx
The owner can switch on and off the light. [YES]
But supposedly, the random phone number CAN NOT and will never have the authority to switch the lights on and off. Only the owner can.
HERE'S MY CURRENT CODE: CCTO
#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=\"+631234567890\"");
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=\"+631234567890\"");
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=\"+631234567890\"");
delay(500);
GPRS.print("Lamp is currently ");
GPRS.println(lampState ? "ON" : "OFF");
GPRS.write( 0x1a );
delay(1000);
}
}
How can I do that?