SM5100B not working

Hi !

I recently bought an Arduino Shield SM5100B.

I’ve been programing a simple code to open an URL and then read the information but I found an inestable response of the shield.

I download examples to work with and adapt to my telephone company and WEB page to read.

Some times the module doesn’t gets the GPRS working. Some times doesn’t get respons. Some times it restars the module.

I worked with arduino 1.0.3 and arduino 1.0.4 with the same instability !

With this code :

#include <SoftwareSerial.h>


SoftwareSerial cell(2,3);  // We need to create a serial port on D2/D3 to talk to the GSM module

const boolean DEBUG          = true;
const String ip = "2.138.140.67"; // IP address of oscarjofre.no-ip.info
const String host = "oscarjofre.no-ip.info"; // required in HTTP 1.1 - what's the name of the host at this IP address?
const String request = "GET /arduino/arduino_sensor.php?type=Celsius&value=29 HTTP/1.1";
//const String request = "GET /arduino/arduino_sensor.php HTTP/1.1";

const String useragent = "Mozilla/5.0"; // for our purposes the user agent doesn't matter - if I understand correctly it's helpful to use something generic the server will recognize
const String apn = "telefonica.es"; // access-point name for GPRS


String s;
/*****************************************
 * Buffers
 */
const int BUFFSIZE = 180;
char at_buffer[BUFFSIZE];
//char buffidx;
char incoming_char = 0;
char buffer[BUFFSIZE];

/*****************************************
 * Registers
 */
boolean firstTimeInLoop = true;
boolean GPRS_registered = false;
boolean GPRS_AT_ready   = false;
boolean continueLoop    = true;
boolean bIsConected     =  false;
boolean GPRS_Error      =  false;

/*********************************************************
 * GPRS Functions
 *********************************************************/
 
/**
 * store the serial string in a buffer until we receive a newline
 */
static int readATString(boolean watchTimeout = false) {
  char c;
  int buffidx = 0;
  int time = millis();
    
  while (1) {
    int newTime = millis();

    if (watchTimeout) {
      // Time out if we never receive a response    
      if (newTime - time > 30000) { GPRS_Error=true; return -1; }//error(ERROR_GSM_FAIL);
    }
    
    if (cell.available() > 0) {
      c = cell.read();
      //Serial.print("-");Serial.print(c);
      if (c == -1) {
        at_buffer[buffidx] = '\0';
        return 0;
      }
      
      if (c == '\n') {
        continue;
      }
            
      if ((buffidx == BUFFSIZE - 1) || c == '\r') {
        at_buffer[buffidx] = '\0';
        return 0;
      }
      
      at_buffer[buffidx++] = c;
    } 
  }

}
/**
 * Send an AT command to the cell interface
 */
static int sendATCommand(const char* ATCom) {
  cell.println(ATCom);
  Serial.print("COMMAND: ");
  Serial.println(ATCom);
  
  while (continueLoop) {
    if (readATString(true)==-1) return -1;
    ProcessATString();
    //Serial.print("RESPONSE: ");
    //Serial.println(at_buffer);
  }
  
  continueLoop = true;
  delay(500);
}




/*
 * Handle response codes
 */
static void ProcessATString() {

  Serial.print("RESPONSE: ");
  Serial.println(at_buffer);
  
  if (strstr(at_buffer, "+SIND: 1" ) != 0) {
    firstTimeInLoop = true;
    GPRS_registered = false;
    GPRS_AT_ready = false;
    
    // GPS unit pulls enough current to keep the GSM shield from starting
    // So we wait until it's initialized and then power it via a digital pin
    //digitalWrite(GPS_RELAY, HIGH);
  }
  
  if (strstr(at_buffer, "+SIND: 10,\"SM\",0,\"FD\",0,\"LD\",0,\"MC\",0,\"RC\",0,\"ME\",0") != 0 
    || strstr(at_buffer, "+SIND: 0") != 0) {
    Serial.println("ERROR SIM invalid");  
    GPRS_Error=true;//error(ERROR_SIM_UNAVAIL);
  }
  
  if (strstr(at_buffer, "+SIND: 10,\"SM\",1,\"FD\",1,\"LD\",1,\"MC\",1,\"RC\",1,\"ME\",1") != 0) {
    Serial.println("SIM card Detected");
    //successLED();
  }
  
  if (strstr(at_buffer, "+SIND: 7") != 0) {
    Serial.println("ERROR NETWORK FATAL");
    GPRS_Error=true;//error(ERROR_NETWORK_FAIL);  
  }
  
  if (strstr(at_buffer, "+SIND: 8") != 0) {
    GPRS_registered = false;
    Serial.println("GPRS FAIL");   
    GPRS_Error=true;//error(ERROR_NETWORK_FAIL) //error(ERROR_GPRS_FAIL);
  }
  
  if (strstr(at_buffer, "+SIND: 11") != 0) {
    GPRS_registered = true;
    Serial.println("GPRS Registered");
    //successLED();
  }
  
  if (strstr(at_buffer, "+SIND: 4") != 0) {
      GPRS_AT_ready = true;
       Serial.println("GPRS AT Ready");
       //successLED();
  }
  
  if (strstr(at_buffer, "+SOCKSTATUS:  1,0") != 0) {
     //GPRS_Error=true;
     //error(ERROR_HOST);
     continueLoop = false; 
  }
  
  if (strstr(at_buffer, "+CME ERROR: 29") != 0) {
    GPRS_Error=true;
    continueLoop = false;
    return;
  }
  
  if (strstr(at_buffer, "+CME ERROR") != 0) {
    GPRS_Error=true;//error(ERROR_GPRS_UNKNOWN);
  }
  
  if (strstr(at_buffer, "OK") != 0 || strstr(at_buffer, "NO CARRIER") != 0) {
    continueLoop = false;
    //successLED();
  }
  
  if (strstr(at_buffer, "+SOCKSTATUS:  1,1") != 0) {
     continueLoop = false;
  }
}


static bool establishNetwork() {
  while ((GPRS_registered == false || GPRS_AT_ready == false) && GPRS_Error==false) {
    readATString(true);
    ProcessATString();
  }
  return !GPRS_Error;
}

// keep reading characters until we get char c
void waitFor(char c) {
  int time = millis();
  char r; 
  while(1) {
    if(cell.available()>0) {
      r=cell.read();
      //Serial.print("c=(");Serial.print(c);Serial.print(") - "); Serial.print("r=(");Serial.print(r);Serial.println(")");
      if (r == c) {
        delay(100);
        return;
      }
      // Time out if we never receive a response    
    }
    int newTime = millis();
    if (newTime - time > 30000) { GPRS_Error=true; return ; }//error(ERROR_GSM_FAIL);
  }
}

// for eating a single message we expect from the module
// prints out the next message from the module. if it's not the expected value, die
static int waitFor(const char* s,unsigned int timeout=1000) {
  int iReturn;
  Serial.println("RESPONSE WaitFor wiring");
 
  readATString(true);
  //Serial.print("RESPONSE WaitFor (");
  //Serial.print(s);
  //Serial.print(") - (");
  //Serial.print(at_buffer);
  //Serial.println(")");
  
  if (strstr(at_buffer, s) != 0) {
      iReturn=0;
  }else{
      iReturn=-1;
  }
  delay(100); // wait for a tiny bit before sending the next command
  return iReturn;
}

// keep spitting out messages from the module til we get the one we expect
static int waitTil(const char* s) {
  int iSeguir=0;
  while (iSeguir!=-1) {
    iSeguir=readATString(true);
    if (strstr(at_buffer, s) != 0){
      delay(1000); // cause we're probably about to send another command
      return 0;
    }else{
       Serial.print("RESPONSE waiting("+String(s)+"): (");
       Serial.print(at_buffer);
       Serial.println(") iSeguir=(" +String(iSeguir) + ")");
       delay(1000);
    }
  }
  return -1;
}

static int sendData(const char* data) {
 
   Serial.println("Attaching GPRS...");
  sendATCommand("AT+CGATT=1"); if (GPRS_Error) return -1;
  delay(1000);
  
  Serial.println("Setting up PDP Context");
  sendATCommand("AT+CGDCONT=1,\"IP\",\"telefonica.es\""); if (GPRS_Error) return -1;
  delay(2000);
  
  Serial.println("Activate PDP Context");
  sendATCommand("AT+CGACT=1,1"); if (GPRS_Error) return -1;
  delay(2000);  
  
  // Change 0.0.0.0 to reflect the server you want to connect to
  Serial.println("Configuring TCP connection to server");
  sendATCommand("AT+SDATACONF=1,\"TCP\",\"2.138.140.67\",80");
  delay(2000);  
  
  //Serial.println("Configure APN");
  //sendATCommand("AT+CGPCO=0,\"\",\"\", 1"); if (GPRS_Error) return -1;
  //delay(2000);
 
  
    
  /*Serial.println("Socket 1, ASCII 1, TPC 1"); // ASCII format p.111 
  sendATCommand("AT+SDATARXMD=1,1,1"); if (GPRS_Error) return -1;
  delay(2000);
  Serial.println("Set Reintents 12"); //number of retries p.113   
  sendATCommand("AT+TRT=12"); if (GPRS_Error) return -1;
  delay(2000);*/  
    
  Serial.println("Starting TCP Connection");
  sendATCommand("AT+SDATASTART=1,1"); if (GPRS_Error) return -1;
  delay(7000);
  
  Serial.println("Getting status ok=+SOCKSTATUS:  1,1,0102,0,0,0");
  sendATCommand("AT+SDATASTATUS=1"); if (GPRS_Error) return -1;
  delay(4000);
  
  while (strstr(at_buffer, "+SOCKSTATUS:  1,1,0102,0,0,0") == 0)
  {
     waitTil("OK"); //OK
     delay(1000);
     Serial.println("Socket NOT connected");
     sendATCommand("AT+SDATASTATUS=1"); if (GPRS_Error) return -1;
     delay(4000);
    
  } 
  waitTil("OK"); //OK //OK
  delay(2000);

  Serial.println("Socket connected");
  Serial.println("Sending data");
    
  // we're now connected and can send HTTP packets!
  int packetLength = 26+host.length()+request.length()+useragent.length(); // 26 is size of the non-variable parts of the packet, see SIZE comments below
  
  Serial.println("Sending HTTP packet...");
  cell.print("AT+SDATATSEND=1,"+String(packetLength)+"\r");
  waitFor('>'); // wait for GSM module to tell us it's ready to recieve the packet
  cell.print(request+"\r\n"); // SIZE: 2
  cell.print("Host: "+host+"\r\n"); // SIZE: 8
  cell.print("User-Agent: "+useragent+"\r\n\r\n"); // SIZE: 16
  cell.write(26); // ctrl+z character: send the packet
  waitFor("OK");
  
  delay(2000);
  
  Serial.println("Wait Til OK...");
  waitTil("OK");
  Serial.print("RESPONSE: ");
  Serial.println(at_buffer);
  if (GPRS_Error) return -1;
  
  Serial.println("Getting status");
  sendATCommand("AT+SDATASTATUS=1"); if (GPRS_Error) return -1;
  delay(2000);
  Serial.println("Getting data 1");
  sendATCommand("AT+SDATAREAD=1"); if (GPRS_Error) return -1;
  delay(2000);
  Serial.println("Getting data 2");
  sendATCommand("AT+SDATAREAD=1"); if (GPRS_Error) return -1;
  delay(2000);
  Serial.println("Wait Til +SDATA...");
  waitTil("SDATA"); if (GPRS_Error) return -1;
  
    
  Serial.println("Close connection");
  sendATCommand("AT+SDATASTART=1,0"); if (GPRS_Error) return -1;
  delay(2000);
  
  Serial.println("Disable PDP Context");
  sendATCommand("AT+CGACT=0,1"); if (GPRS_Error) return -1;
  delay(2000);
  
  // Clear string and flash LED
  // myStr.begin();
  //successLED();
  
  return 0;
 
}

void setup()
{  
  Serial.begin(9600);
  Serial.println("Arduino GPRS ++ Inicialitzant");
  cell.begin(9600);
  
}
void loop()
{
  Serial.println("Inici loop ..."); 
  if (!bIsConected) {
    Serial.println("Establint connexio ..."); 
    bIsConected=establishNetwork();
    
  }
  if (bIsConected && !GPRS_Error) {
    Serial.println("Inici enviament dades ..."); 
    // Send data to cell network
    sendData("");
 
  }
  
  
  if (GPRS_Error) {
     Serial.println("Loop... Fi enviar data ERROR REINICIAR..."); 
     GPRS_registered =  false;
     GPRS_AT_ready   =  false;
     continueLoop    =  true;
     bIsConected     =  false;
     GPRS_Error      =  false;
     //Reiniciar Modul
     
     Serial.println("COMMAND: AT+CFUN=1,1"); 
     delay(2000);
     cell.println("AT+CFUN=1,1");
     waitTil("OK");
     Serial.print("RESPONSE AT+CFUN: ");Serial.println(at_buffer);
      
     delay(2000);
     //ProcessATString();
       
  }else{
    Serial.println("Loop... Fi enviar dades TOT OK..."); 
    delay(5000);
   
  }
  
  
}

i have this test result in the same place with 2 minuts delay:

TEST 1

Arduino GPRS ++ Inicialitzant
Inici loop ...
Establint connexio ...
RESPONSE:      
RESPONSE: +SIND: 1
RESPONSE: 
RESPONSE: +SIND: 10,"SM",1,"FD",1,"LD",1,"MC",1,"RC",1,"ME",1
SIM card Detected
RESPONSE: 
RESPONSE: +SIND: 11
GPRS Registered
RESPONSE: 
RESPONSE: +SIND: 3
RESPONSE: 
RESPONSE: +SIND: 4
GPRS AT Ready
Inici enviament dades ...
Attaching GPRS...
COMMAND: AT+CGATT=1
RESPONSE: 
RESPONSE: OK
Setting up PDP Context
COMMAND: AT+CGDCONT=1,"IP","telefonica.es"
RESPONSE: 
RESPONSE: OK
Activate PDP Context
COMMAND: AT+CGACT=1,1
RESPONSE: 
RESPONSE: OK
Configuring TCP connection to server
COMMAND: AT+SDATACONF=1,"TCP","2.138.140.67",80
RESPONSE: 
RESPONSE: OK
Starting TCP Connection
COMMAND: AT+SDATASTART=1,1
RESPONSE: 
RESPONSE: OK
Getting status ok=+SOCKSTATUS:  1,1,0102,0,0,0
COMMAND: AT+SDATASTATUS=1
RESPONSE: 
RESPONSE: +SOCKSTATUS:  1,1,0102,0,0,0
Arduino GPRS ++ Inicialitzant
Inici loop ...
Establint connexio ...


TEST 2
Arduino GPRS ++ Inicialitzant
Inici loop ...
Establint connexio ...
RESPONSE:      
RESPONSE: +SIND: 1
RESPONSE: 
RESPONSE: +SIND: 10,"SM",1,"FD",1,"LD",1,"MC",1,"RC",1,"ME",1
SIM card Detected
RESPONSE: 
RESPONSE: +SIND: 11
GPRS Registered
RESPONSE: 
RESPONSE: +SIND: 3
RESPONSE: 
RESPONSE: +SIND: 4
GPRS AT Ready
Inici enviament dades ...
Attaching GPRS...
COMMAND: AT+CGATT=1
RESPONSE: 
RESPONSE: OK
Setting up PDP Context
COMMAND: AT+CGDCONT=1,"IP","telefonica.es"
RESPONSE: 
RESPONSE: OK
Activate PDP Context
COMMAND: AT+CGACT=1,1
RESPONSE: 
RESPONSE: OK
Configuring TCP connection to server
COMMAND: AT+SDATACONF=1,"TCP","2.138.140.67",80
RESPONSE:      
RESPONSE: +SIND: 1
RESPONSE: 
RESPONSE: +SIND: 10,"SM",1,"FD",1,"LD",1,"MC",1,"RC",1,"ME",1
SIM card Detected

TEST3
Arduino GPRS ++ Inicialitzant
Inici loop ...
Establint connexio ...
RESPONSE:      
RESPONSE: +SIND: 1
RESPONSE: 
RESPONSE: +SIND: 10,"SM",1,"FD",1,"LD",1,"MC",1,"RC",1,"ME",1
SIM card Detected
RESPONSE: 
RESPONSE: +SIND: 11
GPRS Registered
RESPONSE:      
RESPONSE: +SIND: 1
RESPONSE: 
RESPONSE: +SIND: 10,"SM",1,"FD",1,"LD",1,"MC",1,"RC",1,"ME",1
SIM card Detected
RESPONSE: 
RESPONSE: +SIND: 11
GPRS Registered
RESPONSE: 
RESPONSE: +SIND: 3
RESPONSE: 
RESPONSE: +SIND: 4
GPRS AT Ready
Inici enviament dades ...
Attaching GPRS...
COMMAND: AT+CGATT=1
RESPONSE: 
RESPONSE: OK
Setting up PDP Context
COMMAND: AT+CGDCONT=1,"IP","telefonica.es"
RESPONSE: 
RESPONSE: OK
Activate PDP Context
COMMAND: AT+CGACT=1,1
RESPONSE: 
RESPONSE: OK
Configuring TCP connection to server
COMMAND: AT+SDATACONF=1,"TCP","2.138.140.67",80
RESPONSE: 
RESPONSE: OK
Starting TCP Connection
COMMAND: AT+SDATASTART=1,1
RESPONSE: 
RESPONSE: OK
Getting status ok=+SOCKSTATUS:  1,1,0102,0,0,0
COMMAND: AT+SDATASTATUS=1
RESPONSE: 
RESPONSE: +SOCKSTATUS:  1,1,0102,0,0,0
Arduino GPRS ++ Inicialitzant
Inici loop ...
Establint connexio ...
RESPONSE: 
RESPONSE: +STCPC:1

Seems to be inestable the response of the module.

Any suggest ?

Thank’s.

Hi again!

I already SOLVE my problem. It was the power supply. With the USB was not enough power to send information with the GPRS SM5100 module and

the arduino restarts with no sense.

But I’m really sad because programming with AT command is very hard. I suggest to sparkfun implements a lib to get all the power of this

module because with AT commands directly we can’t get all the functionalities of this code.

Here is my code. It has control error to restart if there is any problem with the communication.

This code saves the temperature and humidity into a WEB page. Any suggest please tell me.

#include <stdarg.h>
#include <SoftwareSerial.h>
#include "DHT.h"

/*************************  DHT  ********************/
#define DHTPIN 4     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE);

float fHumita;
float fTemper;

/************************ SoftSerial ****************/
SoftwareSerial cell(2,3);  // We need to create a serial port on D2/D3 to talk to the GSM module

const String host = "xxxxx.no-ip.info"; // required in HTTP 1.1 - what's the name of the host at this IP address?
const String useragent = "Mozilla/5.0"; // for our purposes the user agent doesn't matter - if I understand correctly it's helpful to use something generic the server will recognize

int packetLength=0;

/*****************************************
 * Buffers
 */
const int BUFFSIZE = 180;
char at_buffer[BUFFSIZE];
//char buffidx;
char incoming_char = 0;
char buffer[BUFFSIZE];

/*****************************************
 * Registers
 */
boolean firstTimeInLoop = true;
boolean GPRS_registered = false;
boolean GPRS_AT_ready   = false;
boolean continueLoop    = true;
boolean bIsConected     = false;
boolean GPRS_Error      = false;
boolean sockStatusReady = false;
boolean sockAllSend = false;


/*********************************************************
 * GPRS Functions
 *********************************************************/
 
/**
 * store the serial string in a buffer until we receive a newline
 */
static int readATString(boolean watchTimeout = false) {
  char c;
  char buffidx = 0;
  int time = millis();
    
  while (1) {
    int newTime = millis();

    if (watchTimeout) {
      // Time out if we never receive a response    
      if (newTime - time > 30000) { GPRS_Error=true; return -1; };//error(ERROR_GSM_FAIL);
    }
    
    if (cell.available() > 0) {
      c = cell.read();
      if (c == -1) {
        at_buffer[buffidx] = '\0';
        return 0;
      }
      
      if (c == '\n') {
        continue;
      }
            
      if ((buffidx == BUFFSIZE - 1) || c == '\r') {
        at_buffer[buffidx] = '\0';
        return 0;
      }
      
      at_buffer[buffidx++] = c;
    } 
  }

}
/**
 * Send an AT command to the cell interface
 */
static int sendATCommand(const char* ATCom) {
  cell.println(ATCom);
  Serial.print("COMMAND: ");
  Serial.println(ATCom);

  while (continueLoop) {
    if (readATString(true)==-1) return -1;
    ProcessATString();
    Serial.print("RESPONSE: ");
    Serial.println(at_buffer);
  }
  
  continueLoop = true;
  delay(200);
}




/*
 * Handle response codes
 */
static void ProcessATString() {

  Serial.println(at_buffer);
  
  if (strstr(at_buffer, "+SIND: 1" ) != 0) {
    firstTimeInLoop = true;
    GPRS_registered = false;
    GPRS_AT_ready = false;
    
  }
  
  if (strstr(at_buffer, "+SIND: 10,\"SM\",0,\"FD\",0,\"LD\",0,\"MC\",0,\"RC\",0,\"ME\",0") != 0 
    || strstr(at_buffer, "+SIND: 0") != 0) {
    Serial.println("ERROR SIM invalid");  
    GPRS_Error=true;
  }
  
  if (strstr(at_buffer, "+SIND: 10,\"SM\",1,\"FD\",1,\"LD\",1,\"MC\",1,\"RC\",1,\"ME\",1") != 0) {
    Serial.println("SIM card Detected");

  }
  
  if (strstr(at_buffer, "+SIND: 7") != 0) {
    Serial.println("ERROR NETWORK FATAL");
    GPRS_Error=true;  
  }
  
  if (strstr(at_buffer, "+SIND: 8") != 0) {
    GPRS_registered = false;
    Serial.println("GPRS FAIL");   
    GPRS_Error=true;
  }
  
  if (strstr(at_buffer, "+SIND: 11") != 0) {
    GPRS_registered = true;
    Serial.println("GPRS Registered");
 }
  
  if (strstr(at_buffer, "+SIND: 4") != 0) {
      GPRS_AT_ready = true;
       Serial.println("GPRS AT Ready");
  }
  
  if (strstr(at_buffer, "+SOCKSTATUS:  1,0") != 0) {
     continueLoop = true; 
     sockStatusReady = false;
  }
  
  if (strstr(at_buffer, "+CME ERROR: 29") != 0) {
    GPRS_Error=true;
    continueLoop = false;
    return;
  }
  
  if (strstr(at_buffer, "+CME ERROR") != 0) {
    GPRS_Error=true;
  }
  
  if (strstr(at_buffer, "OK") != 0 || strstr(at_buffer, "NO CARRIER") != 0) {
    continueLoop = false;
 }

  if (strstr(at_buffer, "+SOCKSTATUS:  1,1") != 0) {
    // return 0 if they don't match or if amount of data is 0
    int checkSocket=checkSocketString2(); 
 
if (checkSocket != 0 ) {
       sockAllSend = true;
    }
     continueLoop = true;
     sockStatusReady = true;
  }
  //TODO: +CLIP: "xxxx",129
  if (strstr(at_buffer, "+CLIP:") != 0) {
    // return 0 if they don't match or if amount of data is 0
    
  }
  
}

static bool establishNetwork() {
  while ((GPRS_registered == false || GPRS_AT_ready == false) && GPRS_Error==false) {
    readATString(true);
    ProcessATString();
   }
  return !GPRS_Error;
}

// keep reading characters until we get char c
static void waitFor(char c) {
  //int time = millis();
  //int newTime=0;
  while(1) {
    delay(100);
    if(cell.available()>0) {
      incoming_char=cell.read();    //Get the character from the cellular serial port.
      if (incoming_char == c) {
          delay(100);
          return;
      }
      // Time out if we never receive a response    
    }
    //newTime = millis();
    //if (newTime - time > 30000) { GPRS_Error=true; return ; }//error(ERROR_GSM_FAIL);
  }
}

// for eating a single message we expect from the module
// prints out the next message from the module. if it's not the expected value, die
static int waitFor(const char* s,unsigned int timeout) {
  int iReturn;
  readATString(true);
  if (strstr(at_buffer, s) != 0) {
      iReturn=0;
  }else{
      iReturn=-1;
  }
  delay(100); // wait for a tiny bit before sending the next command
  return iReturn;
}

// keep spitting out messages from the module til we get the one we expect
static int waitTil(const char* s) {
  int iSeguir=0;
  while (iSeguir!=-1) {
    iSeguir=readATString(true);
    if (strstr(at_buffer, s) != 0){
      delay(100); // cause we're probably about to send another command
      return 0;
    }else{
       delay(100);
    }
  }
  return -1;
}


static void sendData(const char* data) {
 
   sendATCommand("AT+CGACT=1,1"); if (GPRS_Error) return ; //Activate PDP Context
   
   sendATCommand("AT+SDATACONF=1,\"TCP\",\"xx.xx.xx.x\",80"); //Configuring TCP connection to server
 
   
  //Serial.println("Start TCP Connection");
  sendATCommand("AT+SDATASTART=1,1"); if (GPRS_Error) return ;
  delay(1000);
  
  sockStatusReady=false;
  sendATCommand("AT+SDATASTATUS=1"); if (GPRS_Error) return ;
  delay(500);
  int nNumIte=1;
  while (!sockStatusReady && nNumIte++<30)
  {
     sendATCommand("AT+SDATASTATUS=1"); if (GPRS_Error) return ;
     delay(500);
  } 
  if (nNumIte>=30) { GPRS_Error=true; return; }
  Serial.println("Socket connected");
    
  //dtostrf(value, width, precision, output);
  char cTemper[10];  char cHumita[10]; char cTemHum[60];
  dtostrf(fTemper,1,2,cTemper);
  dtostrf(fHumita,1,2,cHumita);
  
  sprintf(cTemHum,"fTemper=%s&fHumita=%s HTTP/1.1",cTemper,cHumita);
  Serial.print("cTemHum:");
  Serial.println(String(cTemHum));
  
  String request="GET /arduino/guardaTemHum.php?tTipTem=Celsius&"+String(cTemHum); //+"&fHumita="+String(cHumita);
 
  // we're now connected and can send HTTP packets!
  int packetLength = 26+host.length()+request.length()+useragent.length(); // 26 is size of the non-variable parts of the packet, see SIZE comments below
  
  Serial.print("Mem="); Serial.println(freeRam());

  Serial.println("HTTP packet"); //Serial.println(String(packetLength));
  cell.print("AT+SDATATSEND=1,"+String(packetLength)+"\r");
  waitFor('>'); // wait for GSM module to tell us it's ready to recieve the packet
  cell.print(request+"\r\n"); // SIZE: 2
  cell.print("Host: "+host+"\r\n"); // SIZE: 8
  cell.print("User-Agent: "+useragent+"\r\n\r\n"); // SIZE: 16
  cell.write(26); // ctrl+z character: send the packet
  delay(200);
  waitTil("OK");  if (GPRS_Error) return ;
  
  sockAllSend=false;
  sendATCommand("AT+SDATASTATUS=1"); if (GPRS_Error) return ;
  delay(500);
  
  nNumIte=1;
  while (!sockAllSend && sockStatusReady && nNumIte++<30)
  {
     sendATCommand("AT+SDATASTATUS=1"); if (GPRS_Error) return ;
     delay(500);
  } 
  if (nNumIte>=30) { GPRS_Error=true; return; }
    
  sendATCommand("AT+SDATASTATUS=0"); if (GPRS_Error) return ;
 
  sendATCommand("AT+SDATASTART=1,0"); if (GPRS_Error) return ;
  
  sendATCommand("AT+CGACT=0,1"); if (GPRS_Error) return ;
  delay(1000);
}


/************************************ DHT *****************************/
static bool dadesTempHumi() {

  fHumita = dht.readHumidity();
  fTemper = dht.readTemperature();
  if (isnan(fHumita) || isnan(fTemper)) {
    return false;
  } else {
    return true;
  }
  
}


void setup()
{  
  Serial.begin(9600);
  cell.begin(9600);
  dht.begin();
  Serial.println("GPRS Inicialitzant");
  
}
void loop()
{
  Serial.println("Inici loop"); 
  Serial.print("mem="); Serial.println(freeRam());
 
  if (!bIsConected) {
    Serial.println("Connexio"); 
    bIsConected=establishNetwork();

    if (bIsConected) {
        sendATCommand("AT+CGDCONT=1,\"IP\",\"internet\""); if (GPRS_Error) return ;  //Setting up PDP Context
        sendATCommand("AT+CGPCO=0,\"CLIENTE\",\"telefonica.es\", 1"); if (GPRS_Error) return ; //Configure APN
   }
    
  }
  if (bIsConected && !GPRS_Error) {
    Serial.println("Send dades"); 
    // Send data to cell network
    if (dadesTempHumi())
        sendData("");
  }
  if (GPRS_Error) {
     Serial.println("ERROR"); 
     GPRS_registered =  false;
     GPRS_AT_ready   =  false;
     continueLoop    =  true;
     bIsConected     =  false;
     GPRS_Error      =  false;
     //Reiniciar Modul
     
     //Serial.println("AT+CFUN=1,1"); 
     delay(2000);
     cell.println("AT+CFUN=1,1");
     waitTil("OK");
      
     delay(2000);

  }else{
    Serial.println("END OK"); 
    delay(500);
  }
}

int freeRam () {
  extern int __heap_start, *__brkval; 
  int v; 
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
}

// receive string such as "SOCKSTATUS: 1,1,0102,10,10,0"
static int checkSocketString2() {

  int nComa=0,nSend=0,nAck=0;
  char cSend[10],cAck[10];
  
  for (int i=0; i<BUFFSIZE; i++) {
      if (at_buffer[i]==',') nComa++;
      if (nComa==3 && at_buffer[i]!=',') cSend[nSend++]=at_buffer[i];
      if (nComa==4 && at_buffer[i]!=',') cAck[nAck++]=at_buffer[i];
      if (nComa==5) i=BUFFSIZE;    
  }
  if (atoi(cSend)==atoi(cAck)) return atoi(cSend);
  return 0;
    
}

Thank’s.

Oscar.