GPS Tracking Device


We often want to keep in track of such things which are much precious to us. For such things, we seek for any best possible means to secure it. These things can be car, truck, containers, and even our loved ones ;). This device was built to perform the particular task.

The main idea for this device is to keep it portable and handy, with the people in touch with the global location of this device and some other information achieved by interfacing sensors to this device. Although, we also intended to control things, using it. Let us suppose that your car has been stolen, so if you wish to, you can simply turn the car off, using any internet facility after covering some encryption.

0

We chose GSM based tracking system because its cheap and by using its GPRS connectivity we can either send the data with higher frequency, due to few number of bytes for information and for actuation. Its range its vast enough that it can work across the country wherever the GSM SIM’s vendor signal are available. The basic idea was to update the database on the server using this device. Therefore, it is another meaningful reason for using GSM for easy GPRS accession.

A GUI based application was equally necessary to provide a user the facility to easily track his device whenever he wishes too. The software can also plot the route between different time intervals.

 


INSIDE HARDWARE

The GPS Tracking Device is controlled throughout by ATMEL’s ATMega32U4 microcontroller. The block diagram is clearly illustrating the whole process.

 GPS Tracking Device Block Diagram

Figure 1 - Block Diagram

The ATMEL’s ATMega32U4 communicates with GPS and GSM Module over UART with a BAUD Rate of 4800. Since the microcontroller has only one UART for communication, we need to seek several other options for communicating with a single UART to GPS and GPS Module.

Since we just need a receiver RX pin from GPS module, because it samples the data each second over UART with a predefined BAUD Rate of 4800. Therefore, we just need to multiplex the two RX from GPS and another from GSM, with the control selection from microcontroller. The multiplexer IC used for multiplexing is 74LS257. It has quad 2-line-to-1-line data selectors/multiplexers (with non-inverted 3-state outputs).

Now I will explain in brief the working and operation of both the modules.


 

       I.            GPS Module - GR89

Overview

GR89 is a product from HOLUX Company. HOLUX Technology Inc. is a professional consumer GPS (Global Positioning System) products provider. It was established in 1994. Since then, they develop and sell GPS and RF products. Current products include Handheld GPS, GPS Receiver and GPS module.

2

Figure 2 - GR89 - GPS Module

HOLUX GR-89 is a high performance, low power consumption, small size, very easy integrated GPS module designed for a broad spectrum of OEM system applications. This product is based on the proven technology found in other HOLUX 20 channel GPS receivers and SiRF GSC3f chipset solution. The GPS module will track up to 12 satellites at a time while providing fast time-to-first-fix and one-second navigation updates. Its far reaching capability meets the sensitivity requirements of car navigation as well as other location-based applications. Therefore, HOLUX GR-89 module is very fit to the customers who devote themselves to AVL system integration and location-based service.

The GR-89 design utilizes the latest surface mount technology (BGA) and high level circuit integration to achieve superior performance while minimizing space and power requirements. This hardware capability combined with software intelligence makes the board easy to be integrated and used in all kinds of navigation applications or products. The application system may communicate with the module set via two RS232 compatible bi-directional communication channels with CMOS 3V voltage level.

 

 

Features

 

1.SiRF GSC3f chipset with embedded ARM7TDMI CPU available for customized applications in firmware.

2.20-Channel GPS Receiver for fast acquisition and reacquisition.

3.Very compact size, only 25.4 x 25.4 x 3 mm.

4.200,000 effective correlators for fast Time To First Fix (TTFF), even at poor satellite signal.

5.Built-in WAAS/EGNOS Demodulator.

6.Low power consumption with Advanced Trickle-Power and Push-To-Fix mode.

7.Support NMEA-0183 v2.2 data protocol and SiRF binary code.

8.Real time navigation for location based services.

9.For Car Navigation, Marine Navigation, Fleet Management, AVL and Location-Based Services, Auto Pilot, Personal Navigation or touring devices, Tracking devices/systems and Mapping devices application.

Operation

The GR89 by default samples the data including GPS Coordinates, Date, Time and various related fields each second, with a BAUD Rate of 4800. This BAUD Rate is configurable. “Global Positioning System Fix Data (GGA)” called as GPGGA includes the data for global position. While date and time can be fetched by the “Recommended Minimum Specific GNSS Data (RMC)” called as GPRMC. The logic, used for programming the controller, behind fetching the data is given below:

This function polled until the UART receives ‘GPGGA’ totally. On calling this function, one must be sure that he is going to receive ‘GPGGA’

 

uint8_t findGPGGA()
{
      char buff;
      while(1)
      {
Position_0:
            buff = USART_getc();
            if(buff == 'G')
            {
Position_1:
                  buff = USART_getc();
                  if(buff == 'P')
                  {
Position_2:
                        buff = USART_getc();
                        if(buff == 'G')
                        {
Position_3:
                              buff = USART_getc();
                              if(buff == 'G')
                              {
Position_4:              
                                    buff = USART_getc();
                                    if(buff == 'A')         return 1;
                                    else if(buff == 'P')    goto Position_2;
                                    else                    goto Position_0;
                              }
                              else if(buff == 'P')    goto Position_2;
                              else                    goto Position_0;
                        }
                        else                    goto Position_0;
                  }
                  else if (buff = 'G')    goto Position_1;
                  else                    goto Position_0;
            }
      }      
            
}

Code 1 - GPGGA finding loop
 
This function polled until the UART receives ‘GPRMC’ totally. On calling this function, one must be sure that he is going to receive ‘GPRMC’.

uint8_t findGPRMC()
{
      char buff;
Position_10:
      buff = USART_getc();
      if(buff == 'R')
      {
Position_11:      buff = USART_getc();
            if(buff == 'M')
            {
Position_12:                   
                  buff = USART_getc();
                  if(buff == 'C')         return 1;
                  else if(buff == 'R')    goto Position_11;
                  else                    goto Position_10;
            }
            else if(buff == 'R')    goto Position_11;
            else                    goto Position_10;
      }                  
      else                    goto Position_10;
}

Code 2 - GPRMC finding loop

Now to read values and then storing the latitude, longitude, date and time defined in the globally defined variables. Note, the function fillString() and findChar() has dedicated task to start reading and storing the no. of characters one by one into the string defined in the argument and returning the hold to the program after a specified char has been found respectively.

void readGPS()
{
      SELECT_GPS;
      findGPGGA();
      findChar(',',5);
      fillString(CURRENT_UTC_TIME,6);
      findChar(',',5);
      fillString(CURRENT_LAT,9);
      findChar(',',5);
      findChar(',',5);
      fillString(CURRENT_LONG,10);
      findGPRMC();
      for(int k = 0; k<9; k++)
            findChar(',',15);
      fillString(CURRENT_DATE,6);
}

Code 3 - Reading GPS function

   II.            GSM Module - SIM900

Overview

The GSM module SIM900 is the product of SIMCOM Internationals. This is a complete Quad-band GSM/GPRS module in a SMT type and designed with a very powerful single-chip processor integrating AMR926EJ-S core, allowing you to benefit from small dimensions and cost-effective solutions.

Featuring an industry-standard interface, the SIM900 delivers GSM/GPRS 850/900/1800/1900MHz performance for voice, SMS, Data, and Fax in a small form factor and with low power consumption. With a tiny configuration of 24mm x 24mm x 3 mm, SIM900 can fit almost all the space requirements in your M2M applications, especially for slim and compact demands of design.

The modem needed only 3 wires (TX, RX, GND) except Power supply to interface with microcontroller/Host PC. Using this modem, you will be able to send and read SMS, connect to internet via GPRS through simple AT commands.

 3

Figure 3 - SIM900 GSM Module


GPRS Command Set

Its datasheet lists various commands and their response types over different conditions. To power-up the GSM module, PWR_KEY must be pulled down for 2-3 seconds. As in our case we are using the GPRS connectivity for porting our data to a free server by a free hosting service, I will just explain you the commands related to it.

Initialization Procedure

Bearer Settings for Applications based on IP - AT+SAPBR

Format: AT+SAPBR = <cmd_type>,,[,]

<cmd_type>

0     Close Bearer

1     Open Bearer

2     Query Bearer

3     Set Bearer Parameters

4     Get Bearer Parameters

5Save the Values of Parameters to NVRAM

                    User-defined for particular profile settings

 

< ConParamTag >

“CONTYPE”           Type of Internet connection.

“APN”                    Access point name string: maximum 50 characters.

“USER”                  User name string: maximum 50 characters.

“PWD”                   Password string: maximum 50 characters.

“PHONENUM”      Phone number for CSD call.

“RATE”                  CSD connection rate.

< ConParamValue_ConType >

“CSD”                    Circuit-switched data call.

“GPRS”                  GPRS connection.

 

Set HTTP Parameter Value - AT+SAPBR

Format: AT+ HTTPPARA=< HTTPParamTag>,

< HTTPParamTag >

“CID”                     (Mandatory Parameter) bearer profile identifier refer to AT+SAPBR

“URL”                    (Mandatory Parameter) HTTP client URL

                                          "http://'server'/'path':'tcpPort' "

                                          "server": FQDN or IP-address

                                          "path": path of file or directory

                                          "tcpPort":

                                          If param. is omitted the service connects to HTTP default port 80.

Steps

1.Setting bearer parameter, connection type to GPRS:

AT+SAPBR=3,1,"Contype","GPRS"

2.Setting Access Point Name:

AT+SAPBR=3,1,"APN","myAPN"

3.Opening bearer:

AT+SAPBR=1,1

4.Now initializing HTTP:

AT+HTTPINIT

5.Setting configuration to 1 as defined above in SAPBR:

AT+HTTPPARA="CID",1

 

Loop Procedure

HTTP Method Action - AT+HTTPACTION

Format: AT+HTTPACTION =

< Method >

0.GET

1.POST

2.HEAD

Read the HTTP server response - AT+HTTPREAD

Format: AT+ HTTPREAD=<start_address><byte_size>

<start_address>     The starting point for data output.

<byte_size>                         The length for data output.

Steps

1.Setting target URL to HTTP parameters, we can also specify optional data by giving parameters:

AT+HTTPPARA="URL","example.com"

(AT+HTTPPARA="URL","example.com?data1=301&data2=420")

2.After applying HTTPACTION to 0, GET session starts:

AT+HTTPACTION=0

3.It is an optional argument, when in case we want to read the response from the server, basically the data. After HTTP GET method we can read the response. The example below, starts reading from pointer 0 to a size of 2 characters:

AT+HTTPREAD=0,2

4.HTTPTERM terminates the session.

AT+HTTPTERM

 SCHEMATIC

4

Figure 4 - Schematic Diagram

 


INSIDE SOFTWARE

 

       I.            Windows based software

 

The software for windows was built using Visual Studio C#.NET. The code is divided into three parts.

 

1.GMAP.NET.

2.HTTP Web Request (System.NET).

3.XCoolForms for Windows (additional feature).

 

GMAP.NET 

 

The code uses GMap.NET.dll and GMap.NET.WindowsForms.dll to add controls to the form. It’s quite easy and simple to use. First of all the GMapControls are needed to be initialized using:

gMapControl1.SetCurrentPositionByKeywords("Pakistan"); // The country to be focused after map is loaded
gMapControl1.gMapProvider = GMapProviders.GoogleMap;   // The map provider
gMapControl1.MapScaleInfoEnabled = true;
gMapControl1.ForceDoubleBuffer = true;
gMapControl1.RoutesEnabled = true;                     // Map can have Routes
gMapControl1.MinZoom = 2;                              // Minimum zoom level
gMapControl1.MaxZoom = 26;                             // Maximum zoom level
gMapControl1.Zoom = 10;                                // Initial zoom level
gMapControl1.DragButton = MouseButtons.Left;           // Mouse button used for dragging the map

Code 4 - GMAP Initialization Procedure


Placing a Marker on the Map

GMapOverlay myOverlay1 = new GMapOverlay(gMapControl1,"myOverlay1"); //Constructing object for Overlay
myOverlay1.Markers.Add(new gMap.NET.WindowsForms.Markers.GMapMarkerGoogleGreen(new PointLatLng(latitude,longitude)));//Adding a new Marker in the Overlay
gMapControl1.Overlays.Add(myOverlay1);// Adding myOverlay1 to the Control

 Code 5 - Method to place a Marker on the Map

 

Plotting Route on the Map

 

GMapOverlay routes = new GMapOverlay(gMapControl1, "routes");// Constructing object for Overlay
gMapControl1.Overlays.Add(routes);
List
 list = new List
(); // The list of Coordinates to be plotted
list.Add(new PointLatLng(32.710525233333,51.709773683333));
list.Add(new PointLatLng(32.711725983333,51.704725066667)); 
.
.
.
.
list.Add(new PointLatLng(32.713785566667,51.66982365));
GMapRoute r = new GMapRoute(list, "myroute"); // object for routing
r.Stroke.Width = 5;
r.Stroke.Color = Color.Red;
routes.Routes.Add(r);
gMapControl1.ZoomAndCenterRoute(r);
gMapControl1.Zoom = 15;</pointlatlng></pointlatlng> 
 

Code 6 - Plotting route on the Map

 

ToolTip

To display related information of pointers we need to add tooltip functionality to it. It can be added using these code segments.

GMapOverlay myOverlay1 = new GMapOverlay(gMapControl1, "myOverlay1");
GMapMarkerGoogleGreen CurrentMarker;
CurrentMarker = new GMap.NET.WindowsForms.Markers.GMapMarkerGoogleGreen(new PointLatLng(latitude, longitude));
CurrentMarker.ToolTipMode = MarkerTooltipMode.OnMouseOver;
CurrentMarker.ToolTipText = "Your Text Here!";
myOverlay1.Markers.Add(CurrentMarker);
gMapControl1.Overlays.Add(myOverlay1); 

Code 7 - Adding tooltip to each marker

HTTP Web Request

Fetching the Data from Server

 The following request will return data from the server stored by a GPS Device and save it as a string.

 

WebRequest request = WebRequest.Create("<a href="http://www.Abc......">http://www.Abc......</a>"); // If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials; // Get the response.
WebResponse response = request.GetResponse(); // Display the status.
Console.WriteLine(((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();            // Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);          // Read the content.
string responseFromServer = reader.ReadLine();                                          // Display the content. 

	

Code 8 - HTTP Web Request

 

Additional Features

XCoolForms

Although it’s not necessary, We wanted to add a little colors to our dull looking form, so we decided to add XCoolForms for windows in our project, which we got from http://www.codeproject.com/Articles/33716/Fancy-Windows-Forms. This is not a major part of our project and we just wanted to add some colors so the code and explanation for this feature can be found in the given link.

Custom Markers

As an additional feature we also added custom markers in our map like red dot, blue dot, arrow. For this purpose we obtain a custom marker class from http://www.codeproject.com/Articles/32643/GMap-NET-Great-Maps-for-Windows-Forms-and-Presenta 


Photographic view

 

5 

 Figure 5 - GPS Tracking Device without Antennas

 6

 Figure 6 - GPS Tracking Device Application

Tags: Untagged

Comments