Estimados, estoy intentando usar otra librería para el manejo del sim900, hasta ahora lo hacía con comandos AT.
La duda que tengo, es que si el código es correcto, para obtener el sms y extraer los datos.
Desde ya muchas gracias,
#include "SIM900.h"
#include <SoftwareSerial.h>
//If not used, is better to exclude the HTTP library,
//for RAM saving.
//If your sketch reboots itself proprably you have finished,
//your memory available.
//#include "inetGSM.h"
//If you want to use the Arduino functions to manage SMS, uncomment the lines below.
#include "sms.h"
SMSGSM sms;
//To change pins for Software Serial, use the two lines in GSM.cpp.
//GSM Shield for Arduino
//www.open-electronics.org
//this code is based on the example of Arduino Labs.
//Simple sketch to send and receive SMS.
int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];
int notificaciones;
char mensaje;
String nroDetectado;
String str;
char *p;
void setup()
{
notificaciones = 0;
//Serial connection.
Serial.begin(9600);
Serial.println("GSM Shield testing.");
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower.
if (gsm.begin(2400)){
Serial.println("\nstatus=READY");
started=true;
}
else Serial.println("\nstatus=IDLE");
if(started){
//Enable this two lines if you want to send an SMS.
//if (sms.SendSMS("1111111111", "Arduino SMS"))
//Serial.println("\nSMS sent OK");
}
};
void loop()
{
if(started)
{
if(gsm.readSMS(smsbuffer, 160, n, 20))
{
Serial.println(n);
Serial.println(smsbuffer);
String str2(smsbuffer);
str = str2;
Serial.println("---------------");
Serial.println(str);
Serial.println("---------------");
int elenotion = str.indexOf("NOTI-ON"); //para encender notificaciones
if (elenotion>=0)
{
Serial.println("notificacinoes");
notificaciones = 1; //habilita notificaciones
mensaje = "NOTIF ON";
mensaje_sms(mensaje);
}
}
}
}
void capturaNroEnviado()
{
int elementoComilla = str.indexOf('5');
int elementoSegundaComilla = str.indexOf('"',elementoComilla);
nroDetectado = str.substring(elementoComilla,21);
delay(100);
}
void mensaje_sms(char mensaje){
if(started){
capturaNroEnviado();
string2char(nroDetectado);
//Enable this two lines if you want to send an SMS.
if (sms.SendSMS(p, mensaje))
Serial.println("\nSMS sent OK");
}
}
char* string2char(String command){
if(command.length()!=0){
p = const_cast<char*>(command.c_str());
return p;
}
}