using gsm module for access control

Hi all,

I have a project using a arduino micro to control some shift registers as well as communicate with a uart serial device with a software serial port. A pc based software application I developed send commands to the atmega which in turn either affects the state of a relay or sends a pre-packaged message to the serial device. currently there is no bi-directional communication between the application and arduino. adding this is not a issue and is in the near future.

I would like to use a gsm shield that I have, connected to the arduino via another software serial port to enable and disable the hardware. I would also be the same mechanism for re-enabling the hardware. my concerns and what I am looking for help on is...

how would I check the gsm modem all the time for any new messages and how to parse them for the "code" sent how would I retain a memory even with a power cycle that the current state of the arduino is "diabled" or "enabled" how would I trigger something in the code so that the serial port reports to the software application the hardware is "on" or "off"

any suggestions would be great! thanks

beginit: how would I check the gsm modem all the time for any new messages and how to parse them for the "code" sent

Depends on the GSM shield, but usually they come with example software that demonstrates it.

how would I retain a memory even with a power cycle that the current state of the arduino is "diabled" or "enabled"

EEPROM

how would I trigger something in the code so that the serial port reports to the software application the hardware is "on" or "off"

HardwareSerial::write()

its a seeed studio sim900 board - could not find that much info on it from their site…

on the first topic - do you have any examples I could use as a foundation - code that continually checks for new txt messages, and then reads them and based on what it reads creates an output?

http://www.seeedstudio.com/wiki/GPRS_Shield_V1.0

Looks like there is good information there on how to set it up and start sending AT commands. Then it would be a matter of sending the right AT commands to read the text messages.

ok guys… working though and need some help. I have this code running in my loop, and my goal is to

  1. when the gsm receives a text on myserial2 the code checks for the index, opens the message with cmgr and then checks the body for a “yes” or “no” as message body.
  2. based on that it runs 2 possible processes.
  3. it ends by deleting all messages with at+cmdl 1,4

I know I only have the very beginning, but am hoping there may be a better way. right now this is in my main loop…

   while(mySerial2.available() > 0){
     inCharModem = mySerial2.read();
      if (indexModem < 5){
         if (inCharModem == '+'){    
           indexModem = 0;
         }
         
         inDataModem[indexModem] = inCharModem;
         indexModem++;
         inDataModem[indexModem] = '\0';
       }
     
     else
       {
         indexModem = 0;
         Serial.write(mySerial2.read());
       }
   }
       if(strcmp(inDataModem,"+CMTI")==0) { indexModem = 0; mySerial2.println("AT+CMGR=7"); }
}

Full code, not snippets.

full code

#include <SoftwareSerial.h>

SoftwareSerial mySerial2(7, 8); 
SoftwareSerial mySerial1(10, 11);

int SER_Pin = 6;  
int RCLK_Pin = 3;  
int SRCLK_Pin = 4; 


#define number_of_74hc595s 1 


#define numOfRegisterPins number_of_74hc595s * 8

String stringOne;


boolean registers[numOfRegisterPins];
char inData[6];
char inChar;
byte index =0;

char inDataModem[6];
char inCharModem;
byte indexModem =0;


void setup(void) {
  Serial.begin(9600);
  mySerial2.begin(19200);
  mySerial1.begin(9600);  

  pinMode(SER_Pin, OUTPUT);
  pinMode(RCLK_Pin, OUTPUT);
  pinMode(SRCLK_Pin, OUTPUT);
  
  
  pinMode(5, OUTPUT);
  pinMode(2, OUTPUT);    
  pinMode(13, OUTPUT); 
  pinMode(9, OUTPUT); 

  //reset all register pins
  clearRegisters();
  writeRegisters();  

}

//set all register pins to LOW
void clearRegisters(){
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
     registers[i] = LOW;
  }
  digitalWrite(5, HIGH);
  digitalWrite(2, LOW);  
} 

void writeRegisters(){

  digitalWrite(RCLK_Pin, LOW);

  for(int i = numOfRegisterPins - 1; i >=  0; i--){
    digitalWrite(SRCLK_Pin, LOW);

    int val = registers[i];

    digitalWrite(SER_Pin, val);
    digitalWrite(SRCLK_Pin, HIGH);

  }
  digitalWrite(RCLK_Pin, HIGH);

}

//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
  registers[index] = value;
}

  
void loop(){
  
   while (Serial.available() > 0) {
     {
       if (index <5)
       {
         inChar = Serial.read();
         if (inChar == '!'){
           index = 0;
         }
         
         inData[index] = inChar;
         index++;
         inData[index] = '\0';
       }
       else
       {
         index = 0;
       }
     }
     if (index == 5){
              if(strcmp(inData,"!0000")==0) {Serial.println("OK");}
              if(strcmp(inData,"!0100")==0) {mySerial2.println("AT");} 


    if (indexModem <5)
       {
         inCharModem = mySerial2.read();
         if (inChar == '+'){    
           indexModem = 0;
         }
         
         inDataModem[indexModem] = inCharModem;
         indexModem++;
         inDataModem[indexModem] = '\0';
       }
       else
       {
         indexModem = 0;
       }
       if(strcmp(inDataModem,"+CMTI")==0) { indexModem = 0; mySerial2.println("AT+CMGR=6"); } 

  
}
   }
}