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
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;
}