I am Working on a project to control the system via the GSM messaging Scheme.
eg:- If I send 1
via an SMS to the GSM module, the Arduino would read this message and disable or enable the system.
But I am unable to process the message, since the received message format is;
+CMT: "+91xxxxxxxxx","","17/07/07,21:57:04+08"
#include<SoftwareSerial.h>
SoftwareSerial myGSM(9,10);// Rx and Tx
int a;
int b[5];
int actuator = 5;
void setup()
{
myGSM.begin(9600);
}
void loop()
{
msg_read();
for( int i = 0; i < 5; ++i )
b[i] = (char)0;
}
void msg_read()
{
myGSM.println("AT+CNMI=2,2,0,0,0");//AT command to recieve live SMS
delay(1000);
if (myGSM.available()>0)
{
char c;
char store[30];
c = myGSM.read();
store[30] = c;
int a = 10;
a += 1;
store[a] = 0;
char* command = strtok(c, ",");
while ( command != 0)
{
int i = 0;
b[i] = atoi(command);
command = strtok(0, ",");
i++;
}
}
for( int j = 0;j <= 2; j++)
{
msg_send(b[j]);
}
}
void msg_send(int c[])
{
myGSM.println("AT+CMGF=1");//Sets GSM module in text mode
delay(1000);
myGSM.println("AT+CMGS=\"+91xxxxxxxxxx\"\r");
delay(1000);
if( c[0] == 1)
{
digitalWrite( actuator, HIGH);
myGSM.println("SYSTEM ENABLED");
}
else if( c[0] == 2)
{
digitalWrite(actuator, LOW);
myGSM.println("SYSTEM ENABLED");
}
if( c[1] == 3)
{
myGSM.println("GEOFENCE ENABLED");
}
else if( c[1] == 4)
{
myGSM.println("GEOFENCE DISABLED");
}
}
Requirement
- I need a code that will allow me to recover the message content and compare it with a predefined string.
- Can I use the GSM library with SIM900a module or is it reserved only for GSM shield?
I am using an Arduino Uno.