sending GPS data through GPRS using arduino

iam building arduino tracking system using sim900 GPRS and sparkfun em406 GPS i wrote this code but it only generate the GPS output but it don't send it to my tracking site and the http request don't generate any output what can i change?

#include <SoftwareSerial.h>
#include "Arduino.h"
#include <TinyGPS.h>

#define RXPIN 9
#define TXPIN 10

#define TERMBAUD  19200

// Set this value equal to the baud rate of your GPS
#define GPSBAUD  4800

// Create an instance of the TinyGPS object
TinyGPS gps;
// Initialize the SoftwareSerial library to the pins you defined above
SoftwareSerial uart_gps(RXPIN, TXPIN);
SoftwareSerial mySerial(7, 8);
// This is where you declare prototypes for the functions that will be 
    // using the TinyGPS library.
void getgps(TinyGPS &gps,float &lan, float &lon);
int num=2;
// In the setup function, you need to initialize two serial ports; the 
// standard hardware serial port (Serial()) to communicate with your 
// terminal program an another serial port (SoftwareSerial()) for your 
// GPS.
void setup()
{

  mySerial.begin(19200);  
  // Sets baud rate of your terminal program
  Serial.begin(TERMBAUD);
  // Sets baud rate of your GPS
  uart_gps.begin(GPSBAUD);



  Serial.println("");
  Serial.println("GPS Shield QuickStart Example Sketch v12");
  Serial.println("       ...waiting for lock...           ");
  Serial.println("");
}

// This is the main loop of the code. All it does is check for data on 
// the RX pin of the ardiuno, makes sure the data is valid NMEA sentences, 
// then jumps to the getgps() function.
void loop()
{
  float lat,lon;
  while(uart_gps.available()&&num==2)     // While there is data on the RX pin...
  {
      int c = uart_gps.read();    // load the data into a variable...
      if(gps.encode(c))      // if there is a new valid sentence...
      {
        getgps(gps,lat,lon);         // then grab the data.
        Serial.println(lat);
        Serial.println(lon);
        num=1;
      }
  }
  if(num==2)
  {
   SubmitHttpRequest(lat,lon);
  }

  }
  // The getgps function will get and print the values we want.
  void getgps(TinyGPS &gps,float &lat2,float &lon2)
  {
    // To get all of the data into varialbes that you can use in your code, 
    // all you need to do is define variables and query the object for the 
    // data. To see the complete list of functions see keywords.txt file in 
    // the TinyGPS and SoftwareSerial libs.

    // Define the variables that will be used
    float latitude, longitude;
    // Then call this function
    gps.f_get_position(&latitude, &longitude);
    lat2=latitude;
    lon2=longitude;
    // You can now print variables latitude and longitude
    Serial.print("Lat/Long: "); 
    Serial.print(latitude,5); 
    Serial.print(", "); 
    Serial.println(longitude,5);


    Serial.print("Altitude (meters): "); Serial.println(gps.f_altitude());  
    // Same goes for course
    Serial.print("Course (degrees): "); Serial.println(gps.f_course()); 
    // And same goes for speed
    Serial.print("Speed(kmph): "); Serial.println(gps.f_speed_kmph());
    //Serial.println();

    // Here you can print statistics on the sentences.
    unsigned long chars;
    unsigned short sentences, failed_checksum;
    gps.stats(&chars, &sentences, &failed_checksum);
    //Serial.print("Failed Checksums: ");Serial.print(failed_checksum);
    //Serial.println(); Serial.println();

    // Here you can print the number of satellites in view
    Serial.print("Satellites: ");
    Serial.println(gps.satellites());
   }
  void SubmitHttpRequest(long lat, long lng)
  {
    mySerial.println("AT+CSQ");
    delay(100);

    ShowSerialData();// this code is to show the data from gprs shield, in order to easily see the process of how the gprs shield submit a http request, and the following is for this purpose too.

    mySerial.println("AT+CGATT?");
    delay(100);

    ShowSerialData();

    mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");//setting the SAPBR, the connection type is using gprs
    delay(1000);

    ShowSerialData();

    mySerial.println("AT+SAPBR=3,1,\"viva.bh\",\"CMNET\"");//setting the APN, the second need you fill in your local apn server
    delay(4000);

    ShowSerialData();

    mySerial.println("AT+SAPBR=1,1");//setting the SAPBR, for detail you can refer to the AT command mamual
    delay(2000);

    ShowSerialData();

    mySerial.println("AT+HTTPINIT"); //init the HTTP request

    delay(2000); 
    ShowSerialData();

    mySerial.print("AT+HTTPPARA=\"URL\",\"http://www.example.com/data.php");// setting the httppara, the second parameter is the website you want to access
    mySerial.print("?lat=");
    mySerial.print(lat);
    mySerial.print("&lng=");
    mySerial.print(lng);
    mySerial.println("\"");
    delay(1000);

    ShowSerialData();

    mySerial.println("AT+HTTPACTION=0");//submit the request 
    delay(10000);//the delay is very important, the delay time is base on the return from the website, if the return datas are very large, the time required longer.

    ShowSerialData();

    mySerial.println("AT+HTTPREAD");// read the data from the website you access
    delay(300);

    ShowSerialData();

    mySerial.println("");
    delay(100);
  }

   void ShowSerialData()
  {
    while(mySerial.available()!=0)
    Serial.write(mySerial.read());
  }

thanks

Use code tags. Thanks.

any help please :roll_eyes: :cold_sweat: :frowning:

Which Arduino are you using? You can't listen to two software serial ports at the same time. So, you can listen to the GPS or you can listed to/talk to the GPRS device. GPS data that arrives while you are talking to/listening to the GPRS device will be lost.

You have a lot of string literals occupying SRAM that don't need to.

We can't see your serial output, so we can't begin to guess what you are doing wrong.

Do you know that you can do anything with the GPRS?

iam using arduino uno, and i tried to make an integer that switch between the GPS and gprs by

while(uart_gps.available()&&num==2)     // While there is data on the RX pin...
	{
		int c = uart_gps.read();    // load the data into a variable...
		if(gps.encode(c))      // if there is a new valid sentence...
		{
			getgps(gps,lat,lon);         // then grab the data.
			Serial.println(lat);
			Serial.println(lon);
                        num=1;
		}
	}
if(num==1){
SubmitHttpRequest(lat, lng);
num=2;
}

but also it didn't work

And what adjustments i need to do to solve this problem

mohd9011:
And what adjustments i need to do to solve this problem

Presumably you are not using the hardware serial port for either device because you want to keep it for debugging. So, start debugging.

Iam using there ports the GPS uses 2,3 but when it's connected to the GPRS i disconnect these pins and connect them through 9,10 through wires, and the GPRS connected through 7,8 pins as the data sheet.