Seeeduino GPRS SIM800 Library and repeated TCP connection issues.

Hi All,

I've had a good search around on the internet and can't find an answer to this anywhere, apologies if its been answered elsewhere.

I have used the Seeeduino GPRS library GitHub - Seeed-Studio/Seeeduino_GPRS: Seeeduino GPRS Library to connect to a PHP script and send some variables. I have modified the Seeeduino GPRS_HTTP example sketch as a basis for my app. When i first run the code there is no issue, it connects to the network and posts the data as expected. The code monitors DIO pins for state changes and should post an update if there is a state change detected.

The issue I have is that after the code has been running for a period of time then a state change occurs it will not send the data correctly, I get the "gprs join network error" error.

This is running on an ATMEGA1284p IC with optiboot bootloader and the arduino UNO*PRO pin mapping.

Here is a copy of my code with the API & host removed for security.

/*
  Sketch: GPRS HTTP Test

*/
#include <gprs.h>
#include <SoftwareSerial.h>


char buffer[0];
//char http_cmd[2000] ;
GPRS gprs;


byte lastAState = 2;
byte lastBState = 2;
//byte lastCState = 2;
//byte lastDState = 2;



//char clientData[] = "TEST";

void setup() {

  pinMode (2, INPUT); //Digi ins
  pinMode (3, INPUT); //Digi ins
  pinMode (5, INPUT); //Digi ins
  pinMode (6, INPUT); //Digi ins
  Serial.begin(9600);
  while (!Serial);

  delay(2000);

  gprs.preInit();
}

void loop() {
  alarmStuff();

  delay(5000);
}


void alarmStuff() {
  Serial.println("CHECKING");
  byte temp = 0;


  //Alarm Pin
  temp = digitalRead(2);
  if (temp != lastAState) {
 lastAState = temp;
    if (temp == LOW) {

     sendData("GET /example.php?API=******REMOVED*****&eventtitle=Alert&desc=Front%20Door%20Open&systitle=ALARM%20SYSTEM HTTP/1.0\r\nHost: ******REMOVED*****\r\n\r\n");
    // sendData();
      Serial.println("DONE");
    } else {
     sendData("GET /example.php?API=******REMOVED*****&eventtitle=Alert&desc=Front%20Door%20Closed&systitle=ALARM%20SYSTEM HTTP/1.0\r\nHost: ******REMOVED*****\r\n\r\n");
      
    }
   
  }

  temp = digitalRead(3);
  if (temp != lastBState) {
lastBState = temp;
    if (temp == LOW) {
    //  sendData();
   sendData("GET /example.php?API=******REMOVED*****&eventtitle=Alert&desc=Back%20Door%20Open&systitle=ALARM%20SYSTEM HTTP/1.0\r\nHost: ******REMOVED*****\r\n\r\n");
    } else {
    sendData("GET /example.php?API=******REMOVED*****&eventtitle=Alert&desc=Back%20Door%20Closed&systitle=ALARM%20SYSTEM HTTP/1.0\r\nHost: ******REMOVED*****\r\n\r\n");
    }
    
  }
}


void sendData(char http_cmd[1024]) {

  Serial.println("SENDING DATA");
  gprs.init();
  gprs.join("hologram");


  Serial.println(http_cmd);

  //GET /example.php?API=******REMOVED*****&eventtitle=Alert&desc=TEST&systitle=ALARM%20SYSTEM HTTP/1.1\r\nHost: ******REMOVED*****\r\n\r\n

  //  Serial.println("GPRS - HTTP Connection Test...");

  delay(500);
  while (0 != gprs.init()) {
    delay(1000);
    Serial.println("init error");
  }

  while (0 == gprs.join("hologram, , ")) { //change "cmnet" to your own APN
    Serial.println("gprs join network error");

    delay(2000);
  }
  // successful DHCP
  Serial.print("IP Address is ");
  Serial.println(gprs.getIPAddress());

  Serial.println("Init success, start to connect server...");

  if (0 == gprs.connectTCP("******REMOVED*****", 80)) {
    Serial.println("connect server success");
  } else {
    Serial.println("connect error");
    while (1);
  }


 gprs.sendTCPData(http_cmd);

 
  
  delay(500);
Serial.println("Moving on");

  ///  Serial.println("close");

}

I have also tried with

  gprs.closeTCP();
  gprs.shutTCP();

after each of the uploads.