I am using a SIM900 GSM/GPRS Shield and the SIM900 Lib
The following code works but not great, It will receive the SMS and does what it needs to do but it does not all ways receive stright away some times i need to reset my UNO and when I do that the messages come through then the samething happens.
and then after leaving it for about 10min or less the status changes to IDLE and the blue light turns off my Shield. I have tried using the built in reset on PIN 9 and and use the function below and it does not power up i need to plug out the power and put it back in. when i use the powerUp() and powerDown() in a blank program it works fine.
I have it connected up to a 9v 2amp battery i dont know what else todo.
void powerUp()
{
pinMode(9, OUTPUT);
digitalWrite(9,LOW);
delay(1000);
digitalWrite(9,HIGH);
delay(2000);
digitalWrite(9,LOW);
delay(3000);
}
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
int numdata;
boolean started=false;
char smsCHARbuffer[160];
char n[20];
int i;
String GetMsg;
SMSGSM sms;
void powerUp()
{
pinMode(9, OUTPUT);
digitalWrite(9,LOW);
delay(1000);
digitalWrite(9,HIGH);
delay(2000);
digitalWrite(9,LOW);
delay(3000);
}
void powerDown()
{
pinMode(9, OUTPUT);
digitalWrite(9,LOW);
delay(1000);
digitalWrite(9,HIGH);
delay(2000);
digitalWrite(9,LOW);
delay(3000);
}
void setup()
{
Serial.begin(9600);
if (gsm.begin(2400)){
Serial.println("\nstatus=READY");
started=true;
}
else Serial.println("\nstatus=IDLE");
}
String incomingSMS(){
if(started){
gsm.listen(); // IMPORTANT!!!!
sms.GetSMS(1, n, smsCHARbuffer, 160);
GetMsg=smsCHARbuffer;
if(GetMsg==LastMsg){
}else{
Serial.println(n);
Serial.println(GetMsg);
LastMsg = GetMsg;
sms.DeleteSMS(1);
}
}
return GetMsg;
}
void loop() // run over and over
{
String GetCurrentSMS = incomingSMS();
if(GetCurrentSMS=="command1"){
Serial.println("");
}else if(GetCurrentSMS=="command2"){
Serial.println("");
}else if(GetCurrentSMS=="command3"){
Serial.println("");
}
GetCurrentSMS = "";
Serial.println("Waiting for sms...");
delay(2000);
}