I've written my code again acording to your suggestions, first i don't have the function strcmp, so i made string comparison using this code
a=="+SIND: 11"
and i made the command reading with this code
char* a;
for(i=0;i<=9;i++){
a[i]=cell.read();
}
so my final code is this, but still not working, could you please help me? thanks
#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[9];//Will hold the incoming character from the Serial Port.
int i=0;
int conf_flag=0;
char key_char[4];
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* a;
int flag=0;
int var=0;
cell.print("AT+SBAND=10");
cell.print("AT+CFUN=1, 1");
var=100;
while(var>0){
for(i=0;i<=9;i++){
a[i]=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?");
while(var>0){
for(i=0;i<9;i++){
a[i]=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,\"none\",\"none\",1");
// cell.print("AT+CGPCO=0,"","",1");
cell.print("AT+CGACT=1,1");
while(var>0){
for(i=0;i<2;i++){
a[i]=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(){
int b=0;
char* a;
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
//cell.println("AT+SDATACONF=1,\"TCP\",\"181.51.142.39\", 2510,1"); // servidor temporal
for(i=0;i<2;i++){
a[i]=cell.read();
}
if(a=="OK"){
a=0;
cell.print("AT+SDATASTART=1, 1");
for(i=0;i<28;i++){
a[i]=cell.read();
}
if(a=="+STCPD: 1"){
cell.print("AT+SDATATREAD=1");
if(cell.available() >0)
{
b=cell.read(); //Get the character from the cellular serial port.
Serial.print(b);
}
}
cell.print("AT+SDATASTATUS=1");
for(i=0;i<28;i++){
a[i]=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
// for(i=0;i<9;i++){
// a[i]=cell.read();
// }
// if(a=="+STCPD: 1"){
// a=0;
// Serial.print("datos recibidos por el host remoto");
cell.print("AT+SDATASTART=1,0");
for(i=0;i<2;i++){
a[i]=cell.read();
}
if(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)
{
for(i=0;i<9;i++){
incoming_char[i]=cell.read(); //Get the character from the cellular serial port.
}
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)
{
for(i=0;i<13;i++){
key_char[i]=Serial.read(); //Get the character from the cellular serial port.
}
if (key_char=="conf" || incoming_char=="+SIND: 7")
{
conf_flag=configure();
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=="serv" && incoming_char=="+SIND: 11" ){
send_flag=conection_f();
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");
}
}
}
}