Void loop with several functions

Hello u guys!!! Would like to say thank you for all your help here, my projects is almost complete with your help. I have, hopefully, one last question. I have a code that collects gps, gyro, accel data, then I use gprs and upload data on to freeboard.io via dweet.io. Everything works really well. I am now sending and sms when the resultant vector magnitude calculated of the Accel data exceeds 1.5. This detects impact on the senor. The problem is that this variable (magnitude) does not record fast enough. I hit the sensor but by the time the loop comes around to read it its already set to its rest condition. The entire code is really long, so hopefully just a loop would be enough, gyro data is fast enough to were i can see it updates every few sec on the website. Can I somehow record it faster, or would store it in the array would help? Not sure if array would make a difference as it seems its just not recording fast enough. Thank you guys in advance...

void calc_mag()
{
  Magnitude=sqrt(pow(gForceX,2)+pow(gForceZ,2)+pow(gForceZ,2));
  gprsSerial.print("Magnitude=");
  gprsSerial.println(Magnitude);
}
///////////////////////////////////////////////////////magnitude//////////////////////

void loop() {

  calc_mag();               /// Calculating magnitude to determine resultant 
  gsmFunction();            /// sends HTTPT REQUEST to DWEET.IO
  recordAccelRegisters();  /// Records ACCEL DATA
  recordGyroRegisters();   /// Records GYRO DATA
  readLocation();          /// Records GPS DATA
  calc_mag();             /// Calculating magnitude to determine resultant
  
  if (Magnitude > 1.5)  //loop if Mag certain value send SMS
  {
  sendSMS();            //Sends sms
  }
  
}

You send an HTTP request every time through the loop() function? Not good.

  gsmFunction();            /// sends HTTPT REQUEST to DWEET.IO

You might need an interrupt to detect the hit.

Yes, aarg,not the entire gsm function is going via loop all the time, only the one that sends a request to HTTP, whcih essentially how it dweets Gyro data, it must be this way as i read position of this device. I am new to programming and do not know all the ins and outs:) What should i do different?

KeithRB, can u give me an idea how to implement one? Has been searching for some time cant seems to find any good examples. I am using arduino mega and sim 900 btw.

Thank you guys for your help!!!

How do you handle the server's reply to the HTTP request?

What should i do different?

loop() will run hundreds of not thousands of times a second (depends what you are doing). You may not want that many HTTP requests.

Thank you.

Here is my http request code

Serial.begin(9600);
  gprsSerial.begin(9600);
  Serial.println("Startinggprs");
  
  Wire.begin();
  setupMPU();
  
  
  Serial1.begin(9600); 
  startMillis = millis();
  Serial.println("StartingGPS");


  Serial.println("Con");
  delay(2000);
  Serial.println("Done!...");
  gprsSerial.flush();
  Serial.flush();

  
   // Is GPRS attached?
  gprsSerial.println("AT+CGATT?");
  delay(1000);
  toSerial();

  // Check signal strength
  gprsSerial.println("AT+CSQ ");
  delay(1000);
  toSerial();

  // Set connection type to GPRS
  gprsSerial.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
  delay(2000);
  toSerial();

  // Set the APN
  gprsSerial.println("AT+SAPBR=3,1,\"APN\",\"fast.t-mobile.com\"");
  delay(2000);
  toSerial();

    // Enable GPRS
  gprsSerial.println("AT+SAPBR=1,1");
  delay(10000);
  toSerial();

  // Check to see if connection is correct and get your IP address
  gprsSerial.println("AT+SAPBR=2,1");
  delay(2000);
  toSerial();
// initialize http service
  gprsSerial.println("AT+HTTPINIT");
  delay(2000); 
  toSerial();
  
   // set http param value
   // ToDO : send dynamic value
   gprsSerial.println(String("AT+HTTPPARA=\"URL\",\"http://www.dweet.io/dweet/for/MYTHINGNAME?lat="+ String(latitude)+"&lon="+ String(longitude)+"&forceX="+ String(gForceX)+"&forceY="+ String(gForceY)+"&forceZ="+ String(gForceZ)+"\""));
   delay(4000);
   toSerial();

   // set http action type 0 = GET, 1 = POST, 2 = HEAD
   gprsSerial.println("AT+HTTPACTION=0");
   delay(6000);
   toSerial();

   // read server response
   gprsSerial.println("AT+HTTPREAD"); 
   delay(1000);
   toSerial();

   //gprsSerial.println("");
   gprsSerial.println("AT+HTTPTERM");
   toSerial();
   delay(300);

   gprsSerial.println("");
   delay(10000);

osavchuk: but by the time the loop comes around

The entire code is really long,

Without seeing the entire code how can we know what is going on or where an effective fix might be applied?

You can call lots of functions from loop() - that is the best way to design a program. Have a look at Planning and Implementing a Program Just make sure that each function completes and returns very quickly.

...R

The gprs function takes about 10 seconds to run, I have placed lots of delays, tried shorter delay seems to bug. I wish there would be a way for me to run my gyro accel and magnitude all the time. I hit the sensor and if it happens to be recording it will and send sms but other times its not detecting the hit because GPRS dweet is running and not gyro...I would like to keep hidden my entire code until I present it in school, in two weeks. Just in case, not sure how would it possibly effect my presentation, but I just dont want to take any chances. Thank you for all your help..