hola a todos, quería ver si alguien me puede ayudar, estoy trabajando con el SM5100B GSM Cellular Shield y con una tarjeta arduino uno, estoy tratando de leer los comandos que vienen desde el SM5100B como +SIND 1, +SIND 7, etc. para poder hacer que el desarrollo funcione perfectamente necesito estar monitoreando estos comandos constantemente, para luego poder conectarme con un servidor a traves de TCP/IP. este es el código que he escrito, espero me puedan ayudar.
Gracias
#include <NewSoftSerial.h> //Include the NewSoftSerial library to send serial commands to the cellular module.
#include <string.h> //Used for string manipulations
char incoming_char=0;//Will hold the incoming character from the Serial Port.
int conf_flag=0;
char key_char=0;
int send_flag=0;
NewSoftSerial cell(2,3); //Create a 'fake' serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin.
/////////////////////////////////////////////////////
void setup()
{
//Initialize serial ports for communication.
Serial.begin(9600);
cell.begin(9600);
Serial.print("Starting SM5100B Communication...");
}
///////////////////////////////////////////////////////
int configure(char){
int flag=0;
char a=0;
int var=0;
cell.print("AT+SBAND=10");
cell.print("AT+CFUN=1, 1");
var=100;
while(var>0){
a=cell.read();
if (a=='+SIND: 11'){
var=0;
}
else if(a=='+SIND: 7'){
var=0;
}
else {
var=var-1;
}
}
if(a=='+SIND: 11'){
a=0;
Serial.print('modulo registrado');
cell.println("AT+CGAT?");
a=cell.read();
if (a=='+CGATT: 1'){
a=0;
Serial.print("encontrado servicio GPRS");
cell.print('AT+CGDCONT=1, "IP", "web.colombia.com.co"');
cell.print('AT+CGPCO=0,"","",1');
cell.print("AT+CGACT=1,1");
a=cell.read();
if (a=='OK'){
a=0;
flag=HIGH;
return flag;
}
else{
Serial.print("error al activar el PDP");
flag=LOW;
return flag;
}
}
else if(a=='CGATT: 0'){
a=0;
Serial.print('servicio GPRS no encontrado, inserte una sim card con plan de datos');
flag=LOW;
return flag;
}
}
else if(a=='+SIND: 7'){
a=0;
Serial.print("modulo solo para llamadas de emergencia");
flag=LOW;
return flag;
}
}
////////////////////////////////////////////////////////
int conection_f(char){
char a=0;
int flag=0;
cell.print('AT+SDATACONF=1, "TCP", "74.125.229.248", 80, 1'); // la IP que se encuentra en esta linea es la IP de google, cambiela por la de IP que usted desee
a=cell.read();
if(a=='OK'){
a=0;
cell.print("AT+SDATASTART=1, 1");
cell.print("AT+SDATASTATUS=1");
a=cell.read();
if (a=='+SOCKSTATUS: 1,1,0102,0,0,0'){
a=0;
Serial.print("socket conectado");
cell.print("AT+SDATATSEND=1, 10"); // envio de datos y tramas
cell.print("AT+SDATATREAD=1");
a=cell.read();
if(a=='+STCPD:1'){
a=0;
Serial.print("datos recibidos por el host remoto");
cell.print("AT+SDATASTART=1,0");
a=cell.read();
if(a=='+STCPD:1' || a=='OK'){
Serial.print("conexion terminada con exito");
flag=HIGH;
return flag;
}
}
}
else if(a=='+SOCKSTATUS: 1,0,0104,0,0,0'){
a=0;
Serial.print("socket no conectado");
flag=LOW;
return flag;
}
else{
Serial.print("no se pudo establecer conexion con el servidor");
}
}
}
/////////////////////////////////////////////////////////
void loop(){
//If a character comes in from the cellular module...
if(cell.available() >0)
{
incoming_char=cell.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char);
if (incoming_char=='+SIND: 1'){
Serial.print("espere mientras el modulo se prepara");
}
else if (incoming_char=='+SIND: 7'){
Serial.print("espere mientras el modulo se prepara");
}
else if (incoming_char=='+SIND: 11'){
Serial.print("modulo listo para empezar a transmitir");
}
}
////If a character is coming from the terminal to the Arduino...
if(Serial.available() >0)
{
key_char=Serial.read(); //Get the character coming from the terminal
if (key_char=='conf' || incoming_char=='+SIND: 7')
{
conf_flag=configure(key_char);
if (conf_flag==HIGH){
Serial.print("modulo listo para transmitir");
}
else if (conf_flag==LOW){
Serial.print("modulo no se pudo configurar con exito, intentelo nuevamente");
}
}
if (key_char=='server' && incoming_char=='+SIND: 11' ){
send_flag=conection_f(key_char);
if(send_flag==HIGH){
Serial.print("datos enviados con exito, conexion terminada");
}
else if(send_flag==LOW){
Serial.print("error al enviar los datos intentelo de nuevo");
}
}
}
}