0

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

  1. I need a code that will allow me to recover the message content and compare it with a predefined string.
  2. Can I use the GSM library with SIM900a module or is it reserved only for GSM shield?

I am using an Arduino Uno.

  • Thank you, the guide helped me figure it out. I encoded the message as #xy, where x and y can take 0 and 1. I stored each character sent to the arduino in a variable. char c = myGSM.read(); Continued this until I found '#' and then used if statements to determine if the message was 1 or 0. – Adnan Arif Sait Apr 8 '18 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.