I have problems because sometimes the sim900 operates correctly activating the assigned DO, but then it stops working.
I do not know what else to do, use the code "AT + CMGDA = " "to delete the existing messages in the sim900 but you still got the problem.
I reset the arduino and you noticed the problem, in the attached image you can see how the sms is, incomplete.
SOMEONE CAN SUPPORT ME TO SOLVE THIS INCOVENIENT.
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8); // Configura el puerto serie para el SIM900
char incoming_char = 0; //Variable que guarda los caracteres que envia el SIM900
String mensaje = "";
int LED = 12 ;
int listo=11;
void setup()
{
pinMode( LED, OUTPUT) ; // LED como salida
pinMode(listo,OUTPUT);
inicializaSIM900();
}
void loop()
{
if (SIM900.available() > 0)
{
incoming_char = SIM900.read(); //Guardamos el carácter del GPRS
Serial.print(incoming_char); //Mostramos el carácter en el monitor serie
mensaje = mensaje + incoming_char ; // Añadimos el carácter leído al mensaje
}
identifica_SMS();
}
void inicializaSIM900()
{
digitalWrite(9, HIGH); // Descomentar para activar la alimentación de la tarjeta por Software
delay(1000);
digitalWrite(9, LOW);
SIM900.begin(19200); //Configura velocidad del puerto serie para el SIM900
Serial.begin(19200); //Configura velocidad del puerto serie del Arduino
Serial.println("OK");
delay (1000);
delay(30000); //Tiempo para que encuentre una RED
Serial.println("PIN OK");
SIM900.print("AT+CLIP=1\r"); // Activa la identificación de llamada
delay(100);
SIM900.print("AT+CMGF=1\r"); //Configura el modo texto para enviar o recibir mensajes
delay(1000);
SIM900.print("AT+CNMI=2,2,0,0,0\r"); // Saca el contenido del SMS por el puerto serie del GPRS
delay(1000);
digitalWrite(listo, HIGH);
delay(100);
SIM900.print("AT+CMGDA=\"");
SIM900.println("DEL ALL\"");
}
void identifica_SMS()
{
int led_on = mensaje.indexOf("Encender");
int led_off = mensaje.indexOf("Apagar");
if (led_on >= 0)
{
digitalWrite( LED, HIGH) ;
Serial.println("\nLED ENCENDIDO");
mensaje = "" ; //Bórralo para la próxima vez
delay(200);
mensaje_sms();
}
if (led_off >= 0)
{
digitalWrite( LED, LOW) ;
Serial.println("\nLED APAGADO");
mensaje = "" ; //Bórralo para la próxima vez
delay(200);
mensaje_sms();
}
}
void mensaje_sms()
{
SIM900.print("AT+CMGF=1\r");
delay(100);
SIM900.println("AT+CMGS=\"573xxxxxxxxxxx\"");
delay(100);
SIM900.println("OK_EJECUTADO"); // message to send
delay(100);
SIM900.println((char)26);
delay(100);
SIM900.println();
delay(100);
}