Anyone could share information on Cooking Hack 3G/GPS Module???

Hi everybody,

I’m working on cooking Hack 3G/GPS module (http://www.cooking-hacks.com/index.php/3g-gprs-shield-for-arduino-3g-gps-audio-video-kit.html).
I’ve experienced a lot of trouble ad very “strange” behaviour…especially on string/char management.

I’ve a feeling that this module is far from be “steady” (as the price should guarantee) and support on Arduino integration/coding is not so good.

I succeed in perform very simple and single-purpose project (taking photo, GPS positioning, FTP ecc.) but if I put single pieces together in a more complex project (es. Get request from facebook through php, reading value and than take photo, upload on a site and reply on facebook) the code start become “crazy” when I try to manage String&Char that I use to pass parameter from web (php) to Arduino.

Are there any constraints (ore something like that) on using particular Arduino function/Class? (maybe some “common” resource that create bad response)

thx

I succeed in perform very simple and single-purpose project (taking photo, GPS positioning, FTP ecc.)

Don't sell yourself short. Those are not simple projects.

Get request from facebook through php, reading value and than take photo, upload on a site and reply on facebook

This is a pretty complicated set of steps, involving moving a fair amount of data. I'd not be surprised that you are running out of memory.

the code start become "crazy" when I try to manage String&Char[] that I use to pass parameter from web (php) to Arduino.

Are there any constraints (ore something like that) on using particular Arduino function/Class?

The String function can be a resource hog, resulting in fragmented memory that can be hard to recover. It's best that you not use it in large projects. Everything that the String class does can be done with char arrays. After all, that's what the String class uses as the storage mechanism for its data. Certainly the packaged functionality of endsWith(), startsWith(), etc. makes the class attractive, but there is a (high) price for using the class.

Perhaps, if you posted your code, we'd have something concrete to comment on.

I'd not be surprised that you are running out of memory.

Is there a way to check this?

Is there a way to check this?

At least two.

One is to search for the FreeMemory() method that allocates and frees larger and larger blocks of memory until the allocation fails. It then returns the largest value that succeeded. This is how much memory you have available AT THE TIME THAT THE FUNCTION WAS CALLED.

So, critical selection of where to call the function is important. Function calls take space on the stack, reducing the amount of memory available. Recursive function calls can take up a lot of stack space.

The other is more gray-matter intensive. Post your code and let us apply out gray matter to it.

thanks for reply

I'm trying to optimize the use of string....and clear up code to make it clearer and share what I've done

I'll be back...

here are the Arduino code (WIP) that now have a “less crazy behaviour” due to some optimization on “String” and “Serial.print” funcion usage

Sorry but is not very tidy (and also some italian words)…but I hope could be readable :wink:

Sometimes work, sometimes freeze and other times arrives at the end of the restart from set up…

Its perform following steps.

  1. connect to a PHP files that check for a Facebook post (in ties case a request of a Photo) and return di ID of post (for following reply)
  2. Shoot a Photo, Upload through FTP and reply to post
int led = 13;
int onModulePin = 2;       
char server[ ]="xxx"; 
char port[ ]="80";
int spia = 8;
String chiamata;
String id;

//Parametri per ftp
char ftp_port[ ]="21";
char user_name[ ]="xxx";
char password[ ]="xxxx";
//


void setup(){

    Serial.begin(115200);                // UART baud rate
    delay(2000);
    pinMode(led, OUTPUT);
    pinMode(onModulePin, OUTPUT);
       pinMode(spia, OUTPUT); 
    digitalWrite(spia,HIGH);


    for (int i=0;i< 3;i++){
        delay(5000);
    } 
    
    digitalWrite(spia,LOW);


}

void loop(){

   mobile_action(); //take request from Facebook/php
   shootphoto();  //Shoot photo, upload via FTP and reply to FB Post
   Serial.println("End...");
  while(1);
  
}


  
  void mobile_action()////////////////////////////////////////////////////////////////////////////////////////////
{
   char data[500]; 
   int x;
   
   Serial.println("AT+CGSOCKCONT=1,\"IP\",\"ibox.tim.it\"");  
    while(Serial.read()!='K'); 
   
  
    Serial.print("AT+CHTTPACT=\""); //Connects with the HTTP server
  Serial.print(server);
  Serial.print("\",");
  Serial.println(port);        
 
     x=0;

    do{
        while(Serial.available()==0);
        data[x]=Serial.read();
    //  Serial.println(data);  
        x++;  
      }while(!(data[x-1]=='T'&&data[x-2]=='S'));        //waits for response "REQUEST"
      
   Serial.println("GET /mobile/mobile_action.php HTTP/1.0");
  Serial.println("Host: wooow.altervista.org");
  Serial.println("Content-Length: 0"); 
   
   Serial.write(0x0D);
   Serial.write(0x0A);
   Serial.write(0x0D);
   Serial.write(0x0A);
   Serial.write(0x1A);       //sends ++ 
    
    while(Serial.read()!='K');
    while(Serial.read()!=' ');
  x=0;
  do{
        while(Serial.available()==0);
        data[x]=Serial.read();  
        x++;  
   }while(!(data[x-1]=='/'&&data[x-2]=='<')); //mi fermo quando trovo il primo </

 chiamata=data;
id = chiamata.substring((x-33),(x-2));
 Serial.println(id);

  
  }
 

   void shootphoto()//scatta foto e carica via ftp//////////////////////////////////////////////////////////
{
  
  char name[18];
    
  //Set Up Camera
  
      Serial.println("AT+CCAMS");     //starts the camera
      while(Serial.read()!='K');

    Serial.println("AT+CCAMSETD=640,480");     //sets VGA (640*480) resolution
    while(Serial.read()!='K');

    Serial.println("AT+CCAMSETR=270");     //rotate camera
    while(Serial.read()!='K');
        
    Serial.println("AT+FSLOCA=1");     //stores the image file in the 3G module
    while(Serial.read()!='K');
  
  
  //End SetUp Camera
    
   Serial.println("AT+CCAMTP");     //takes a picture, but not saved it
   while(Serial.read()!='K');  

    Serial.println("AT+CCAMEP");     // saves the picture into C:/Picture    
    Serial.flush();     

    while(Serial.read()!='/');
    while(Serial.read()!='/');

   int x=0;
    do{
        while(Serial.available()==0);
        name[x]=Serial.read();
        x++;
    }while(x < 19);
    
    String file_stringa = String(name);

    Serial.println("AT+CCAME");     // stops the camera
    while(Serial.read()!='K');

  upload(file_stringa.substring(0,19));  //dovuto fare questo giro perchà metteva dei caratteri speciali a fine stringa
}



void upload(String file)//carica foto via ftp/////////////////////////////////////////////////////////////////////////
{
 
  char data[255];
  
     Serial.print("AT+CFTPSERV=\""); //Sets the FTP server
  Serial.print(server);
  Serial.println("\""); 
    Serial.flush();
   int x=0;
    do{
        while(Serial.available()==0);
        data[x]=Serial.read();  
        x++;  
    }while(!(data[x-1]=='K'&&data[x-2]=='O'));

    Serial.print("AT+CFTPPORT=");    //Sets FTP port
  Serial.println(ftp_port);
    Serial.flush();
    x=0;
    do{
        while(Serial.available()==0);
        data[x]=Serial.read();  
        x++;  
    }while(!(data[x-1]=='K'&&data[x-2]=='O'));

    Serial.print("AT+CFTPUN=\""); //Sets the user name
  Serial.print(user_name);
  Serial.println("\""); 
    Serial.flush();
    x=0;
    do{
        while(Serial.available()==0);
        data[x]=Serial.read();  
        x++;  
    }while(!(data[x-1]=='K'&&data[x-2]=='O'));

    Serial.print("AT+CFTPPW=\""); //Sets password
  Serial.print(password);
  Serial.println("\"");     
    Serial.flush();
    x=0;
    do{
        while(Serial.available()==0);
        data[x]=Serial.read();  
        x++;  
    }while(!(data[x-1]=='K'&&data[x-2]=='O'));

    Serial.println("AT+CFTPMODE=1");    //Selects pasive mode
    Serial.flush();
    x=0;
    do{
        while(Serial.available()==0);
        data[x]=Serial.read();  
        x++;  
    }while(!(data[x-1]=='K'&&data[x-2]=='O'));

      
    Serial.print("AT+CFTPPUTFILE=\"/photos/");  //Uploads a test file into FTP server.
    Serial.print(file);
     Serial.println("\",4");
   
    x=0;
    do{
        while(Serial.available()==0);
        data[x]=Serial.read(); 
        x++;  
    }while(!(data[x-1]=='K'&&data[x-2]=='O'));
    
   chiamata = "GET /mobile/reply_mobile.php?id="+id+"&photo=http://wooow.altervista.org/photos/"+file+" HTTP/1.0";
   

  reply();

} 

void reply()
{
  
    char data[400]; 
   int x;
   
   Serial.println("AT+CGSOCKCONT=2,\"IP\",\"ibox.tim.it\"");  
    while(Serial.read()!='K'); 
   
  
    Serial.print("AT+CHTTPACT=\""); //Connects with the HTTP server
  Serial.print(server);
  Serial.print("\",");
  Serial.println(port);        
 
     x=0;
    do{
        while(Serial.available()==0);
        data[x]=Serial.read();

        x++;  
      }while(!(data[x-1]=='T'&&data[x-2]=='S'));        //waits for response "REQUEST"
      
   Serial.println(chiamata);


  Serial.println("Host: wooow.altervista.org");
  Serial.println("Content-Length: 0"); 
   
   Serial.write(0x0D);
   Serial.write(0x0A);
   Serial.write(0x0D);
   Serial.write(0x0A);
   Serial.write(0x1A);       //sends ++ 
    
  
   do{
        while(Serial.available()==0);
        data[x]=Serial.read();
        x++;  
      }while(!(data[x-1]=='#'&&data[x-2]=='#'));        //waits for response "REQUEST"

  }
   char data[500];

On a 328 based Arduino, there went 1/4 of your memory.

    do{
        while(Serial.available()==0);
        data[x]=Serial.read();
    //  Serial.println(data);  
        x++;  
      }while(!(data[x-1]=='T'&&data[x-2]=='S'));        //waits for response "REQUEST"

This will terminate if the serial data contains RUST or PEST or BEST or any number of other words that end in ST. Not a very robust test. The strncmp() function would allow you to specifically test for REQUEST at the end of the string.

Also, there is nothing to stop this code from writing to data[500], data[501], data[502], etc.

 chiamata=data;

You just made a copy of the data in the array that could use up another 1/4 of the memory. Why is it necessary to copy the data? By the way, data is not the best choice for a variable name.

      Serial.println("AT+CCAMS");     //starts the camera
      while(Serial.read()!='K');

Block until the Arduino is reset if the phone does not respond with OK. Is that really what you want?

I’d create a function that read and printed the phone reply, and returned true or false, based on whether the letters OK arrived one after the other. The function should time out after some reasonable (variable?) period of time.

Of course, to do this, the phone really needs to be connected to something other than the hardware serial port. SoftwareSerial could be used to read the phone data, so that the hardware serial port could be used to debug the program.

    String file_stringa = String(name);

This calls the String constructor to make a String object containing the data in the name variable. Then, the copy constructor is called to copy that object’s data to another object (also constructed) named file_stringa.

That’s three constructor calls, when only one is necessary: Two destructor calls are also made.

String file_stringa(name);
  char data[255];

One eighth of the memory on a 328.

    Serial.flush();

I’m 99.999% certain this call is NOT needed, anywhere it is made. Throwing away the phone response is not a good idea (pre 1.0 behavior). Blocking until the pending serial data has all been send is not generally necessary (post 1.0 behavior).

    char data[400];

20% of the 328’s memory.

With all the constant strings in the Serial.print() statements, you are almost certainly running out of memory.

The F() macro can help.
Serial.println(“Host: wooow.altervista.org”);
becomes
Serial.println(F(“Host: wooow.altervista.org));
and your SRAM utilization drops.

You need to carefully consider the sizes of the arrays named data in the various functions. One global array, with a more reasonable size, is going to cut your memory utilization considerably. Dump the String class altogether (or, at least the chiamata instance). The first instance that copies the data in data just so you can use substring() to get id is hugely wasteful.

Thanks PaulS, you certainly focused me various issue and give a lot of useful info to dealing with

a let you know as soon as I get success

Thanks again PaulS, as promised I'm back to tell that (almost) every problem has been solved thanks to your "guide"...

regards matteo

Hi Matteo, could you please share the final code with me? I'm having some issues that I think are the same that you were facing. Thanks!!!

Hi.How to connect this shield with DynDns?I must check my ip first after connection with mobile ISP ( http://checkip.dyndns.com/ ) and then update the dyndns with my new ip http://username:password@members.dyndns.org/nic/update?hostname=yourhostname&myip=ipaddress&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG . Port setup? Code for sketch?Thanks.

@jiber

Find in the following my latest working code (sorry but sometime you’ll find some Italian Words :wink:
Time is gone since I’ve posted my original code so you’ll find something new (Ex some SMS interaction).
Obviously it’s not optimized but works…and is still in progress as my personal Arduino training gym :wink:
I use php (on web server) to perform action (see in the following)

Macro descr.
Arduino connects with a FB Fanpage (starting with an SMS “Start”) I search for request (post with Hashtag such as #photo (request to shoot a photo), #dove6 (request gps position)).
When find request the shield “speech” (I use Google translate to create an AMR file starting from the request (text)) and start to perform request (shoot a photo & upload & reply on FB posting the photo … find GPS position and reply google maps link of the position)
There’s also a function that prints SMS: I use another Arduino connected with Ethernet & a Thermal printer and I use API from http://gofreerange.com/printer project

I hope it could be all useful…

I’ll send 2 reply bcause the code is too long …

cheers

// PART 1

int led = 13;
int onModulePin = 2;        // the pin to switch on the module (without press on button) 
char server[ ]="www.yoursite.com"; //
char port[ ]="YOUR_PORT";
int spia = 8;
char name[18];
int richiesta_foto=0;
int richiesta_gps=0;
int flag_request=0;
int flag_rework=0;

//Parametri per ftp
char ftp_port[ ]="PORT";
char user_name[ ]="USER";
char password[ ]="PWD";
//
char id_fb[10][32];
int y=0;
int ciclo;
char* comando_sms;
String risposta;
 char risposta_seriale[250]; 


void(* Riavvia)(void) = 0; //serve per riavviare 

void switchModule(){
   digitalWrite(spia,HIGH);
    digitalWrite(onModulePin,HIGH);
    delay(2000);
    digitalWrite(onModulePin,LOW);
    for (int i=0;i< 3;i++){
        delay(5000);
    } 
    digitalWrite(onModulePin,HIGH);
    delay(2000);
    digitalWrite(onModulePin,LOW);
    for (int i=0;i< 2;i++){
        delay(5000);
    } 
 digitalWrite(spia,LOW);
}

void setup(){

    Serial.begin(115200);                // UART baud rate
    delay(2000);
    pinMode(led, OUTPUT);
    pinMode(onModulePin, OUTPUT);
    pinMode(spia, OUTPUT);
    digitalWrite(spia,LOW); 
  
  //  switchModule();                    // switches the module ON

    for (int i=0; i<10;i++) //lampeggia prima di partire
    {
      digitalWrite(spia,HIGH); 
      delay(500);
      digitalWrite(spia,LOW);
      delay(500);
    }

  //inizializzo per gestione SMS inbound

  while(1){ Serial.println(F("AT+CMGF=1"));if(check_reply("OK",0)=="ok") {break;}}
    
  while(1){ Serial.println(F("AT+CPMS=\"SM\",\"SM\",\"SM\""));if(check_reply("OK",0)=="ok") {break;} }
     
  while(1){Serial.println(F("AT+CNMI=2,1"));if(check_reply("OK",0)=="ok") {break;}}

//fine inizializzazione SMS inbound


}

void loop(){
  digitalWrite(spia,LOW);
Serial.println("Starting...");

                                                             
comando_sms=sms_inbound();

if (comando_sms=="start")

{
   digitalWrite(spia,HIGH);
     
     while (mobile_action()!="ok") {Serial.println("Riparto...");switchModule();};
     if (flag_request!=0)
     {
    
       delay(7000);

     while (download()!="ok") {delay(5000);};
          delay(7000);

     while (ascolta()!="ok") {delay(5000);};


      if ( richiesta_foto>0 ){ delay(5000);  while (shootphoto()!="ok") {switchModule();};  delay(5000); }
  
     if ( richiesta_gps>0 ) { Serial.println("Parte GPS"); while (calcola_gps()!="ok") {switchModule();}; }
         
       if (richiesta_foto + richiesta_gps >0) {  while (reply()!="ok") {switchModule();} Riavvia();}
         else { Serial.println("Nessuna richiesta"); }
    }
    
 
 }

if (comando_sms=="stampa")
{
digitalWrite(spia,HIGH);
Serial.println("SMS in stampa...");

  }




  flag_request=0;


}


  
  char* mobile_action()////////////////////////////////////////////////////////////////////////////////////////////
{

   int x;
   
   
   
   for (int i=0; i<250; i++) {risposta_seriale[i]='\0'; } //ripulisco buffer
   
   flag_rework=0;
   while(1)
   {
    Serial.println("AT+CGSOCKCONT=1,\"IP\",\"ibox.tim.it\"");
    if(check_reply("OK",0)=="ok") {break;}
   flag_rework++;
  if (flag_rework>2) { Serial.println("Riavvio..."); /*return "ko"*/switchModule();}
  }
  
  flag_rework=0;
  while(1)
   {
    Serial.print(F("AT+CHTTPACT=\"")); //Connects with the HTTP server
    Serial.print(server);
    Serial.print("\",");
    Serial.println(port);        
    if(check_reply("REQUEST",0)=="ok") {break;}
    flag_rework++;
    if (flag_rework>2) { Serial.println("Riavvio..."); /*return "ko"*/switchModule();}
    }
    
    
  Serial.println(F("GET /XXX.php HTTP/1.0"));
  Serial.println(F("Host: YOUR_SITE"));
  Serial.println(F("Content-Length: 0")); 
   
   Serial.write(0x0D);
   Serial.write(0x0A);
   Serial.write(0x0D);
   Serial.write(0x0A);
   Serial.write(0x1A);       //sends ++ 
    
    while(Serial.read()!='K');
    while(Serial.read()!=' ');
  x=0;

  do{
        while(Serial.available()==0);
        risposta_seriale[x]=Serial.read();  
     
       
          if ((risposta_seriale[x-1]=='D'&&risposta_seriale[x-2]=='N')) {Serial.println(F("Nessuna richiesta...."));return "ok";}
          
          
          if ((risposta_seriale[x-1]=='p'&&risposta_seriale[x-2]=='/'))
          {
               richiesta_foto=1;
           
            for (int i=0;i<31;i++) {id_fb[y][i]=risposta_seriale[x-34+i];}
              id_fb[y][31]='\0';
            
              x=0;
              y++;


            }
            
            if ((risposta_seriale[x-1]=='g'&&risposta_seriale[x-2]=='/'))
          {

            richiesta_gps=1;            
            for (int i=0;i<31;i++) {id_fb[y][i]=risposta_seriale[x-34+i];}
              id_fb[y][31]='\0';
              x=0;
              y++;

            }
          
           x++;  
        if (x>250){ x=0;}
   }while(!(risposta_seriale[x-1]=='s'&&risposta_seriale[x-2]=='/')); //mi fermo quando trovo il primo </


Serial.print("Trovate in tutto ");Serial.print(y-1);Serial.println(" stringhe di id");

  for (int i=0;i<y;i++){
    
    Serial.println(id_fb[i]);
    
    }
  flag_request=1;
  return "ok";
  }




char* download()////////////////////////////////////////////////////////////////////////
{

   
   while(1)
   {
    Serial.println(F("AT+CGSOCKCONT=1,\"IP\",\"ibox.tim.it\""));  
   if(check_reply("OK",0)=="ok") {break;}
  }
   

   while(1)
   {
    Serial.print(F("AT+CFTPSERV=\"")); //Sets the FTP server
    Serial.print(server);
    Serial.println(F("\"")); 
     if(check_reply("OK",0)=="ok") {break;}
  }
  


  while(1)
   {
    Serial.print(F("AT+CFTPPORT="));    //Sets FTP port
  Serial.println(ftp_port);
    if(check_reply("OK",0)=="ok") {break;}
  }

  while(1)
   {
   Serial.print(F("AT+CFTPUN=\"")); //Sets the user name
  Serial.print(user_name);
  Serial.println(F("\"")); 
   if(check_reply("OK",0)=="ok") {break;}
  }

 while(1)
   {
   Serial.print(F("AT+CFTPPW=\"")); //Sets password
  Serial.print(password);
  Serial.println(F("\""));     
   if(check_reply("OK",0)=="ok") {break;}
  }
  
  
  while(1)
   {
    Serial.println(F("AT+CFTPMODE=1"));    //Selects pasive mode
 if(check_reply("OK",0)=="ok") {break;}
  }



  for (int i=0;i<y;i++){
    
    while(1)
   {
    Serial.print(F("AT+CFTPGETFILE=\"/mobile/audio/"));  
      Serial.print(id_fb[i]);
       Serial.print(".amr");
       Serial.println(F("\",8"));
     if(check_reply(" 0",0)=="ok") {break;}
    }
   }
 return "ok";    
}

char* ascolta()//////////////////////////////////////////////////////////////////////

{
   while(1)
   {
     Serial.println(F("AT+FSCD=D:/audio"));
    if(check_reply("OK",0)=="ok") {break;}
    }

    
    while(1)
   {
    Serial.println(F("AT+CSDVC=3"));
 if(check_reply("OK",0)=="ok") {break;}
    }

    
    
        for (int i=0;i<y;i++){
       Serial.print(F("AT+CCMXPLAY=\""));  //Uploads a test file into FTP server.
        Serial.print(id_fb[i]);
       Serial.println(".amr\"");
//    if(check_reply("stop",0)!="ok") {Serial.println("errore...riparto"); return "ko";}
  while(check_reply("stop",0)!="ok") {Serial.println("errore...riparto");}  
    }
 return "ok";     
}

second part…

 char* shootphoto()//scatta foto e carica via ftp//////////////////////////////////////////////////////////
{
  

      while(1)
     {
      Serial.println(F("AT+CCAMS"));     //starts the camera
     if(check_reply("OK",0)=="ok") {break;} 
      Serial.println(F("AT+CCAME")); delay(2000); //se non riesce a partire stoppo la camera
    }
   
     while(1)
     {
    Serial.println(F("AT+CCAMSETD=640,480"));     //sets VGA (640*480) resolution
   if(check_reply("OK",0)=="ok") {break;} //meglio avviare la procedura di reset altrimenti loop
    }
   
     while(1)
     {
    Serial.println(F("AT+CCAMSETR=270"));     //rotate camera
   if(check_reply("OK",0)=="ok") {break;} //meglio avviare la procedura di reset altrimenti loop
    }
        
    while(1)
     {
    Serial.println(F("AT+FSLOCA=1"));     //stores the image file in the 3G module
 if(check_reply("OK",0)=="ok") {break;} //meglio avviare la procedura di reset altrimenti loop
    }
    
  
  //End SetUp Camera
      while(1)
     {
   Serial.println(F("AT+CCAMTP"));     //takes a picture, but not saved it
if(check_reply("OK",0)=="ok") {break;} //meglio avviare la procedura di reset altrimenti loop
    }

    Serial.println(F("AT+CCAMEP"));     // saves the picture into C:/Picture    

    while(Serial.read()!='/');
    while(Serial.read()!='/');

   int x=0;
   ciclo =0;
    do{
        while(Serial.available()==0){ciclo++; delay(10); if (ciclo > 1000) { Serial.println("Seriale unavailable, riavvio...");return "td";}};
        name[x]=Serial.read();
        x++;
    }while(x < 19);
   name[19]='\0'; 
   name[15]='\0';
   Serial.print("salvata la foto; ");
   Serial.println(name);

      while(1)
     { Serial.println(F("AT+CCAME"));     // stops the camera
    if(check_reply("OK",0)=="ok") {break;} 
    }

  
  while (upload()!="ok") {delay(5000);};
  return "ok";
}



char* upload()//carica foto via ftp/////////////////////////////////////////////////////////////////////////
{

   
    while(1)
     {Serial.println(F("AT+CGSOCKCONT=2,\"IP\",\"ibox.tim.it\""));  
 if(check_reply("OK",0)=="ok") {break;} 
    }
   
 
 
     while(1)
     {Serial.print(F("AT+CFTPSERV=\"")); //Sets the FTP server
  Serial.print(server);
  Serial.println(F("\"")); 
  if(check_reply("OK",0)=="ok") {break;} 
    }
  

    while(1)
     {Serial.print(F("AT+CFTPPORT="));    //Sets FTP port
  Serial.println(ftp_port);
  if(check_reply("OK",0)=="ok") {break;} 
    }
  

    while(1)
     {Serial.print(F("AT+CFTPUN=\"")); //Sets the user name
  Serial.print(user_name);
  Serial.println(F("\"")); 
if(check_reply("OK",0)=="ok") {break;} 
    }

    while(1)
     {Serial.print(F("AT+CFTPPW=\"")); //Sets password
  Serial.print(password);
  Serial.println(F("\""));     
if(check_reply("OK",0)=="ok") {break;} 
    }


       while(1)
     {Serial.println(F("AT+CFTPMODE=1"));    //Selects pasive mode
if(check_reply("OK",0)=="ok") {break;} 
    }


  while(1)
     {
    Serial.print(F("AT+CFTPPUTFILE=\"/photos/"));  //Uploads a test file into FTP server.
    Serial.print(name);
     Serial.println(F(".jpg\",4"));
    delay(2000);
    if(check_reply("OK",0)=="ok") {break;} 
    }
delay(10000);
if(check_reply(" 0",0)!="ok") {Serial.println("errore...risposta non valida e riparto da capo"); return "ko";} //lascio senza while



Serial.println("Caricato");
return "ok";
   
}

third part…(3/4)

 char* calcola_gps()//////////////////////////////////////////////////////////
{

      
  while(1)
     {Serial.println(F("AT+CGSOCKCONT=2,\"IP\",\"ibox.tim.it\""));  
 if(check_reply("OK",0)=="ok") {break;} 
    }
    
    while(1)
     {Serial.println("AT+CGPSURL=\"supl.google.com:7276\"");         // sets GPS server
 if(check_reply("OK",0)=="ok") {break;} 
    }

     while(1)
     {Serial.println("AT+CGPSSSL=0");         // without certificate
 if(check_reply("OK",0)=="ok") {break;} 
    }
   
     while(1)
     {Serial.println("AT+CGPS=1,2");         // starts GPS session in based mode
 if(check_reply("OK",0)=="ok") {break;} 
    }

  
  int flag_trovato =0;
     
     int posizione;
    int contagiri=1;
    int x;
    
    while (contagiri < 10)
    {
       
     
         // char dataIn[255];
         for (x=0;x< 250;x++){ risposta_seriale[x]='\0';} 
        
          
          x=0;
    
          Serial.println("AT+CGPSINFO"); // request GPS info
   
          do{
       
            while(Serial.available()==0);
    
            risposta_seriale[x]=Serial.read(); 
        
            x++;                        
          }while(!(risposta_seriale[x-1]=='K'&&risposta_seriale[x-2]=='O')); 

          if (x>60) 
          {
                   if (!(risposta_seriale[x-60]==','&&risposta_seriale[x-59]==',')) 
                    {
                      flag_trovato=1;
                      posizione = x-60;
                      Serial.println("Trovato: ");
                      Serial.println(risposta_seriale);
                      Serial.print("POsizione:");Serial.println(posizione);
                      Serial.print("Lat: ");                    for (int i=posizione; i<(posizione+11); i++){Serial.print(risposta_seriale[i]);}
                      Serial.print("Long: ");                    for (int i=posizione+14; i<posizione+26; i++) { Serial.print(risposta_seriale[i]);}
                      
                      
                      
                      break; //Esco
                    }
          }


           contagiri++;
          
         
          delay(12000);
     
          
        Serial.print("Ricerca gps numero:");Serial.println(contagiri);
    }

if (flag_trovato ==1)
    {
      
        boolean flag_caricato = false;
    
              while (!flag_caricato) {
            
                
                        /* while(1)
                         {Serial.println(F("AT+CGSOCKCONT=2,\"IP\",\"ibox.tim.it\""));  
                          if(check_reply("OK",0)=="ok") {break;} 
                          }*/
                               
                      flag_rework=0;
                      while(1)
                       {
                        Serial.print(F("AT+CHTTPACT=\"")); //Connects with the HTTP server
                        Serial.print(server);
                        Serial.print("\",");
                        Serial.println(port);        
                        if(check_reply("REQUEST",0)=="ok") {break;}
                        flag_rework++;
                        if (flag_rework>2) { Serial.println("Riavvio..."); /*return "ko"*/switchModule();}
                        }
                                
                          //ora la chiamata GET....
                          
                           while(1)
                          {
                          Serial.print("GET /mobile/upload_gps.php?lat=");
                          for (int i=posizione; i<(posizione+11); i++){Serial.print(risposta_seriale[i]);}
                          Serial.print("&long=");
                          for (int i=posizione+14; i<posizione+26; i++) { Serial.print(risposta_seriale[i]);}
                          Serial.print("&ns=");
                          Serial.print(risposta_seriale[posizione+12]);
                          Serial.print("&ew=");
                          Serial.print(risposta_seriale[posizione+27]);
                          Serial.print("&alt=");
                          for (int i=posizione+45; i<posizione+50; i++) { Serial.print(risposta_seriale[i]);}
                          Serial.print("&data=");
                          for (int i=posizione+29; i<posizione+35; i++) { Serial.print(risposta_seriale[i]);}
                          Serial.print("&gmt=");
                          for (int i=posizione+36; i<posizione+42; i++) { Serial.print(risposta_seriale[i]);}
                          Serial.println(" HTTP/1.0");
                          Serial.println("Host: YOUR_SITE.COMg");
                          Serial.println("Content-Length: 0"); 
                           
                           Serial.write(0x0D);
                           Serial.write(0x0A);
                           Serial.write(0x0D);
                           Serial.write(0x0A);
                           Serial.write(0x1A);       //sends ++ 
                            if(check_reply("OK",0)=="ok") {break;} 
                          } 
                          
                         // Serial.println("Caricato...");
                          flag_caricato = true;
                          return "ok";
                        
            }
            
    }

    return "ok";
}

Part 4/4…last one (sorry but i haven’t time to upload&share a link)

char*  reply()//////////////////////////////////////////////////////////
{
  

   int x;
   
    flag_rework=0;
    while(1)
     {Serial.println(F("AT+CGSOCKCONT=1,\"IP\",\"ibox.tim.it\""));  
      if(check_reply("OK",0)=="ok") {break;} 
      flag_rework++;
     if (flag_rework>2) { Serial.println("Riavvio..."); return "ko";}
      }
   
  

flag_rework=0;
  while(1)
   {
    Serial.print(F("AT+CHTTPACT=\"")); //Connects with the HTTP server
    Serial.print(server);
    Serial.print("\",");
    Serial.println(port);        
    if(check_reply("REQUEST",0)=="ok") {break;}
    flag_rework++;
    if (flag_rework>2) { Serial.println("Riavvio..."); return "ko";}
    }
  
   flag_rework=0;
  
       if (richiesta_foto>0) 
       {
         Serial.print("GET /YYY.php?photo=http://YOUR_SITE/photos/");
         Serial.print(name);
         Serial.println(".jpg HTTP/1.0");
       }
       else {Serial.println("GET ZZZ.php HTTP/1.0");}
        Serial.println(F("Host: YOUR_SITE.COM"));
        Serial.println(F("Content-Length: 0")); 
         
         Serial.write(0x0D);
         Serial.write(0x0A);
         Serial.write(0x0D);
         Serial.write(0x0A);
         Serial.write(0x1A);       //sends ++ 
        
         //delay(5000);
         x=0;
     do{
        while(Serial.available()==0);
        risposta_seriale[x]=Serial.read();  
   //    Serial.print(risposta_seriale[x]);
       x++;  
       if (x>250){ x=0;}
   }while(!(risposta_seriale[x-1]=='#'&&risposta_seriale[x-2]=='#')); //mi fermo quando trovo il primo </

 
  
    
    return "ok";
 
}
  
  
char* sms_inbound()
{
  

  
while(1)//ciclo attesa ricezione SMS
  { 
          String risposta; //serve per estrarre stringhe
          
            Serial.println("In attesa ...");  
            
            
          int  x=0;
            
              do{//Ora attendo sms
                 while(Serial.available()==0);
                 risposta_seriale[x]=Serial.read();  
                 x++;  
                 if (x>250){ x=0;}
                }while(!(risposta_seriale[x-5]=='M'&&risposta_seriale[x-6]=='S')); 
            
           risposta_seriale[x+1]='\0';
           
      
           
           // String indice_sms = risposta.substring(x-2,x);//serve per accedere a sms tipo delete ATTENZIONE A KO se + di 99 SMS
            

          Serial.print("AT+CMGR=");
         // Serial.println(indice_sms);
          Serial.print(risposta_seriale[x-2]);
          Serial.println(risposta_seriale[x-1]);
          
          
          char x1=risposta_seriale[x-2]; //serve per mantenere il contatore dei caratteri e poi cancellarlo
          char x2=risposta_seriale[x-1];         
          
          x=0;
          
          do{ //estraggo testo e sender del SMS
                        while(Serial.available()==0);
                        risposta_seriale[x]=Serial.read();  
                        x++;  
                        if (x>250){ x=0;}
                
             }while(!(risposta_seriale[x-2]=='O'&&risposta_seriale[x-1]=='K'));  
           risposta_seriale[x]='\0';
           
          risposta = risposta_seriale;

                
           int pos_testo=0;
           int lung_tot=x; //lunghezza totale risposta che contiene testo sms, sender ecc.
       
         while(1)
         {
            if (risposta_seriale[x]=='"'){break;}
            x--; 
           pos_testo++; //trovo la posizione del carattere successivo ad ultimo "
           }
       
       /* estrazione testo sms

        for (int i=(lung_tot-pos_testo+3); i<lung_tot-5; i++)
        {
         Serial.print(risposta_seriale[i]);          
         }
         
        /* estrazione sender
        for (int i=36; i<49; i++)
        {
         Serial.print(risposta_seriale[i]);          
         }
         */
        
         //cancello SMS
           Serial.print("AT+CMGD=");
           Serial.print(x1);
           Serial.println(x2);      
    
        risposta.toLowerCase(); //metto tutto il testo in minuscolo
        
         if (risposta.indexOf("reply")!=-1)
         {
         while(1)
           {
              Serial.print("AT+CMGS=\"");   // send the SMS number
              for (int i=36; i<49; i++) //recupero il sender
              {
               Serial.print(risposta_seriale[i]);          
               }
              Serial.println("\""); 
              delay(1500);      
              Serial.print("ricevuto...");     // the SMS body
              delay(500);
              Serial.write(0x1A);       //sends ++ = CTRL Z
           if(check_reply("OK",0)=="ok") {break;}
           }  
         }  
         
          if (risposta.indexOf("start")!=-1)
         {
          return "start";
          }
         
         if (risposta.indexOf("stampa")!=-1)
         {
                         while(1)
                 {
                  Serial.println("AT+CGSOCKCONT=1,\"IP\",\"ibox.tim.it\"");
                  if(check_reply("OK",0)=="ok") {break;}
                }
              
                while(1)
                 {
                  Serial.print(F("AT+CHTTPACT=\"")); //Connects with the HTTP server
                  Serial.print(server);
                  Serial.print("\",");
                  Serial.println(port);        
                  if(check_reply("REQUEST",0)=="ok") {break;}
                  flag_rework++;
                  
                  }
                  
                  Serial.print("GET /printer/print_sms.php?sms=");
                 for (int i=(lung_tot-pos_testo+3); i<lung_tot-5; i++)
                  {
                    if (risposta_seriale[i]==' ') Serial.print('+');
                    else Serial.print(risposta_seriale[i]);          
                 }
                
                Serial.println(" HTTP/1.0");
                Serial.println(F("Host: YOUR_SITE"));
                Serial.println(F("Content-Length: 0")); 
                 
                 Serial.write(0x0D);
                 Serial.write(0x0A);
                 Serial.write(0x0D);
                 Serial.write(0x0A);
                 Serial.write(0x1A);       //sends ++  
                
                digitalWrite(spia,HIGH);
                delay(10000);
                  digitalWrite(spia,LOW);
                  
                        return "stampa";
          }


         return "none";               
    Serial.println("return none");     
           
  }  
}

 char* check_reply(char* check, int trace)
{
 
    char risposta[255];
    int x=2;
     ciclo=0;
  do{
        while(Serial.available()==0){ ciclo++; delay(10); if (ciclo > 1000){return "td";}};
        risposta[x]=Serial.read();
        x++;  
        if (x>255) {x=2; }
        if (trace==1) {Serial.print(risposta[x]);}
        if ((risposta[x-1]=='R'&&risposta[x-2]=='R'&&risposta[x-3]=='E')) {return "ko";}
      }while(!(risposta[x-1]==check[1]&&risposta[x-2]==check[0]));    
      
     if (trace==1) {Serial.print("trovato valore corrispondente a:"); Serial.println(check[1]);Serial.println(check[0]); }
  return "ok";
 }

sorry but i haven't time to upload&share a link

You can just attach a file to a post. It's in Additional Options... under the text entry box.

thx dxw00d

Thank you very much for your response. I really appreciate this! I'll let you know if this solve my issue. Thanks again. Best regards!

Hi,

i don't know if you are interesterd, but i created a library for this shiled available on my site http://wooo.altervista.org/arduino-3g-gps-shield/