arduino tracking system

new product release, exhibitions/ trade shows, promotions, contests, or any other contents (videos/tutorials) that are useful to the community.

Moderators: lily.li, violet

Post Reply
mohd9011
Pre-kindergarten
Pre-kindergarten
Posts: 1
Joined: Sat May 24, 2014 12:46 am

arduino tracking system

Post by mohd9011 » Sat May 24, 2014 12:55 am

hi there
iam building a tracking system as my final year project and iam using arduino uno, sparkfun em406 GPS, sim900 v1.4 GPRS, i tried running the GPS and it's giving me the coordinates and the GPRS shield is connecting to the site through HTTP request but when i combine them together, the GPS don't generate any data and stuck at the "waiting for lock" message and none of the GPRS outputs appear on the screen

p.s: the spaces so the the site accept my post

this the code i use, where did i go wrong and what can i do?

Code: Select all

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

#define RXPIN 9
#define TXPIN 10
SoftwareSerial mySerial(7, 8);

#define TERMBAUD  19200
#define GPSBAUD  4800
TinyGPS gps;
SoftwareSerial uart_gps(RXPIN, TXPIN);
void getgps(TinyGPS &gps);
void SubmitHttpRequest(long lat, long lng);

void setup()
{
 
  // Sets baud rate of your terminal program
  Serial.begin(TERMBAUD);
  // Sets baud rate of your GPS
  uart_gps.begin(GPSBAUD);
  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,\"myapn\",\"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.begin(19200);               // the GPRS baud rate   
  
  
  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())     // 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);
			SubmitHttpRequest(lat, lng)
		}
	}
  }
void SubmitHttpRequest(long lat, long lng)
{
 
  mySerial.println("AT+HTTPINIT"); //init the HTTP request
 
  delay(2000); 
  ShowSerialData();
 
  mySerial.print("AT+HTTPPARA=\"URL\",\"my site php url");// 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.
  //while(!mySerial.available());
 
  ShowSerialData();
 
  mySerial.println("AT+HTTPREAD");// read the data from the website you access
  delay(300);
 
  ShowSerialData();
 
  mySerial.println("");
  delay(100);
}

// 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);
  
  // Same goes for date and time
  int year;
  byte month, day, hour, minute, second, hundredths;
  gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);
  // Print data and time
  Serial.print("Date: "); Serial.print(month, DEC); Serial.print("/"); 
  Serial.print(day, DEC); Serial.print("/"); Serial.print(year);
  Serial.print("  Time: "); Serial.print(hour, DEC); Serial.print(":"); 
  Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC); 
  Serial.print("."); Serial.println(hundredths, DEC);
  //Since month, day, hour, minute, second, and hundr
  
  // Here you can print the altitude and course values directly since 
  // there is only one value for the function
  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 ShowSerialData()
{
  while(gprsSerial.available()!=0)
    Serial.write(gprsSerial.read());
}
thanks :)

Post Reply