Hi everyone!
I'm running GSMv2 on ArduinoMega to read number from webpage which then interacts with other code - plays LED animation with TLC5940.
I've set up GPRS connection so that it can parse HTTP request while running main loop() as parallel to this there is LED animation running with TLC, reading Bluetooth module etc.
Problem is: when GSM shield makes connection with client.connect(); it freezes the main loop for a second So the animation freezes, everything pauses for a second... How can I solve this problem? Part of the code is below:
void startGSM()
    {
      // /////////START GSM/////////////
      // After starting the modem with GSM.begin()
      // attach the shield to the GPRS network with the APN, login and password
      if (gsmAccess.begin(PINNUMBER) == GSM_READY)
      {
        Serial.println("PIN correct = GSM READY");
      }
      else
      {
        Serial.println("PIN error");
        delay(500);
      }
      if (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)
      {
        Serial.println("APN correct = GPRS READY");
      }
      else
      {
        Serial.println("APN error");
        delay(500);
      }
      // /////////START GSM/////////////
    }
  unsigned long updateHashtag()
  {
    GPRScurrentMillis = millis();
    // if you get a connection, report back via serial:
//Waiting 30sec to connect again
    if (GPRScurrentMillis - GPRSstartMillis >= GPRSPeriod)
    {
      Serial.println("");
      Serial.println("Updating HT...");
      Serial.println("Connecting...");
///AND PART BELOW is what i think hangs the main loop for a second..
      if (client.connect(server, port))
      {
        Serial.println("Searching for hashtag: " + hashtag);
        client.print("GET ");
        client.print(path + hashtag);
        client.println(" HTTP/1.1");
        client.print("Host: ");
        client.println(server);
        client.println("Connection: close");
        client.println();
      }
      else
      {
        // if you didn't get a connection to the server:
        Serial.println("connection failed");
      }
      GPRSstartMillis = GPRScurrentMillis;
    }
    // ////////////////parser start'/////////////
    // ////////////////parser start'/////////////
  //THIS JUST READS php PAGE i've set up with number #323412 (or whatever) and outputs 323412
    if (client.available() > 0)
    {
      // Serial.println("HT client available.");
      cHT = client.read();
      if (cHT == '#')
      {
        writeBool = true;
      }
      if (writeBool == true)
      {
        Serial.print(cHT);
        hashtag_buffer[HTindex] = cHT; // appending characters to buffer array
        HTindex++;
        if (cHT == '\n')
        {
          hashtag_buffer[0] = '0'; //removing # character
          hashtag_buffer[HTindex - 2] = '\0';
          Serial.println("returning result and setting HTindex to 0..");
          unsigned long hashtag_result_int = atol(hashtag_buffer);
          testBool = true; // switch test bool so we can test again
          HTindex = 0; // reset hashtag_buffer
          Serial.println(hashtag_result_int);
          writeBool = false;
          return hashtag_result_int;
        }
      }
    }
    // //////////////parser END/////////////
  }
 void setup()
{
Serial.begin(9600);
 // setting up mega serial
 BTserial.begin(38400); // HC-05 default serial speed for AT mode is 38400
 // Wait for hardware to initialize
 delay(1000);
  // ////Starting BT /////////////
 //initHC05ToInq(); // Set correct states for inq
 //initMessage();
 //BTserial.println("AT+INQ");
 // ////Starting BT /////////////
// /////////TLC5940//////////
 Tlc.init();
 // /////////TLC5940//////////
 startMillis = millis(); // initial start time
 ANIMstartMillis = millis();
 GPRSstartMillis = millis();
 ////////GSM///////////
 startGSM();// starting GSM
 }
void loop()
{
whiteSnake(3);/// PLAY LED ANIMATION WITH TLC
int BTtotal = updateBTmodule();Â ///CHECK BLUETOOTH
unsigned long HTtotal = updateHashtag(); /// CONNECT to GPRS
currentMillis = millis();
ANIMcurrentMillis = millis()
}