Help Making SIM800L Connect TCP Faster

I have a software that is getting vehicle GPS position and a voltage read every 6 seconds, store the data in a variable as an array and after 5 GPS locations have been stored send the data via TCP Connection. After i send the data to the server the variable holding the data is cleared and start the GPS collection again. My code is a variation from OpenTracker.

The problem i have is that sometimes the TCP connection is not made, and the data is cleared before any sending can be done.

I need some help to improve the code to make it that if there is an error in TCP Connection, try sending the info again.

I also need some advise when the TCP takes a while to make te conn, the GPS intervals will be too far apart, maybe keep the GPS always saving data every 6 seconds, even if the GPRS is making a connection to the server.

Hardware used

  • ESP8266 NodeMcu
  • Ublox Neo-6M GPS
  • SIM800L EVB GPRS Module
  • INA219 Current Sensor Module

OpenTracker Source

My GSM variation to work with SIM800L

int gsm_send_data_current() {
  
  Serial.print(F("gsm_send_data_current(): sending data."));
  Serial.println(data_current);

  gsm_port.println( F("AT") );
  status_delay(1000);

  gsm_port.println( F("AT+CIPSHUT") );
  status_delay(1000);

  gsm_port.println( F("AT+CIPSTATUS") );
  status_delay(1000);

  gsm_port.println( F("AT+CIPMUX=0") );
  status_delay(1000);

  gsm_port.println( F("AT+CSTT=\"internet.movistar.ni\",\"movistarni\",\"movistarni\"") );//start task and setting the APN,
  status_delay(1000);
  gsm_show_data();
  
  gsm_port.println( F("AT+CIICR") );//bring up wireless connection
  status_delay(1000);
  gsm_show_data();
  
  gsm_port.println( F("AT+CIFSR") );//get local IP adress
  status_delay(1000);
  gsm_show_data();
  
  gsm_port.println( F("AT+CIPSPRT=0") );
  status_delay(1000);
  gsm_show_data();

  gsm_port.println( F("AT+CIPSTART=\"TCP\",\"162.214.10.80\",\"5015\"") );//start up the connection
  status_delay(2000);
  gsm_show_data();
  
  gsm_port.println( F("AT+CIPSEND") );//begin send data to remote server
  status_delay(1000);
  gsm_show_data();

  gsm_port.print( data_current );
  status_delay(1000);
  gsm_show_data();

  gsm_port.println((char)26);//sending
  status_delay(1000);//waiting for reply, important! the time is base on the condition of internet
  
  gsm_port.println( F("AT+CIPSHUT") );//close the connection
  Serial.println(F("gsm_send_data_current(): completed"));
  
  return 1;
}

I 'll suggest not to use TCP connection for that but a direct HTTP call.

I use SIM 800 to get data from a server and to send data.

When I get the data from the server, I set the SIM800 as server and get data from TCP. I notice I get 3 blocs of data like this:

REMOTE IP: 99.999.999.9
the message from the server
CLOSED

But between the message and the "CLOSED", it last about 5 sec. So maybe this is what's happening on the server to which you send the data.

So maybe it's would be better to try an HTTP connection to send the data:
AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","thesitetocall.com/insert.php"
AT+HTTPPARA="CONTENT","application/x-www-form-urlencoded"
AT+HTTPDATA=11,5000 -> the first value is the number of bytes you'll send
then you just sim800l.println("data=coucou");
AT+HTTPACTION=1 --> 1 = POST, 0 = GET
AT+HTTPREAD --> read answer from the server
AT+HTTPTERM

In my case I find this faster

Hope this help