Vehicle Tracking System Using GPS and SMS - Mobitek.com.my
Vehicle Tracking System Using GPS and SMS - Mobitek.com.my
Vehicle Tracking System Using GPS and SMS - Mobitek.com.my
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Table of Contents<br />
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
List of Figures ..................................................................................................................................... 3<br />
Acknowledgements........................................................................................................................... 4<br />
Abstract ................................................................................................................................................ 5<br />
Chapter 1: Introduction .................................................................................................................. 6<br />
1.1 General Introduction ........................................................................................................ 6<br />
1.2 Aims <strong>and</strong> Objectives ............................................................................................................. 7<br />
1.3 The <strong>GPS</strong> + GSM modem ..................................................................................................... 8<br />
1.4 GSM modem ............................................................................................................................ 8<br />
1.5 <strong>System</strong> Architecture diagram ............................................................................................ 9<br />
Chapter 2: Literature Review ...................................................................................................... 10<br />
2.1 Programming Languages Required ................................................................................ 10<br />
2.1.1 PHP ................................................................................................................................... 10<br />
2.1.2 Java Script ..................................................................................................................... 10<br />
2.2 XAMPP ..................................................................................................................................... 11<br />
2.3 Adobe Dreamweaver .......................................................................................................... 11<br />
2.4 ODBC ....................................................................................................................................... 11<br />
2.5 <strong>SMS</strong> Engine ........................................................................................................................... 11<br />
2.6 IntelliTrac X1 Wizard .......................................................................................................... 12<br />
2.7 No-IP ....................................................................................................................................... 12<br />
2.8 Google Maps API .................................................................................................................. 12<br />
Chapter 3: Getting Started .......................................................................................................... 13<br />
3.1 Step 1: Create a Microsoft Access Database .............................................................. 14<br />
3.2 Step 2: Configure <strong>and</strong> Test the <strong>SMS</strong> Engine Software ............................................ 16<br />
3.3 Step 3: Configure the ODBC ............................................................................................ 19<br />
3.4 Step 4: Install, Test <strong>and</strong> Configure the IntelliTrac X1 ............................................. 21<br />
3.4.1 Installing the IntelliTrac X1 ...................................................................................... 21<br />
3.4.2 Testing the IntelliTrac X1 .......................................................................................... 22<br />
Akila Wajirakumara Page 1
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
3.4.3 Configuring the IntelliTrac X1 Wizard ................................................................... 23<br />
3.5 Step 5: Adding the Google Maps API ............................................................................ 25<br />
Chapter 4: Creating the Online <strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> ........................................................................ 27<br />
4.1 View Information of all the <strong>Vehicle</strong>s Page ................................................................... 28<br />
4.2 Locate <strong>and</strong> Track the <strong>Vehicle</strong>’s last position Page ..................................................... 29<br />
4.3 Find Closest <strong>Vehicle</strong> to your Location Page ................................................................. 31<br />
4.4 View Complete <strong>Vehicle</strong> Log Page .................................................................................... 32<br />
Chapter 5: Conclusion ................................................................................................................... 33<br />
5.1 Important features of this project .................................................................................. 33<br />
5.2 Practical Implementations ................................................................................................ 34<br />
5.3 Future Development ........................................................................................................... 34<br />
References ........................................................................................................................................ 35<br />
Appendix ............................................................................................................................................ 36<br />
Codes .............................................................................................................................................. 36<br />
Google Maps codes to Locate <strong>and</strong> Track <strong>Vehicle</strong> ........................................................... 36<br />
Functions for Updating the Main Database ..................................................................... 39<br />
Akila Wajirakumara Page 2
List of Figures<br />
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
Figure 1 - IntelliTrac X1 08<br />
Figure 2 - Q24 08<br />
Figure 3 - Table containing all the information of the drivers in the database 14<br />
Figure 4 - <strong>Vehicle</strong> log of all the drivers in the database 15<br />
Figure 5 - Configuring <strong>SMS</strong> Engine 16<br />
Figure 6 - Starting <strong>SMS</strong> Engine 17<br />
Figure 7 - <strong>SMS</strong> Engine Database 18<br />
Figure 8 - ODBC Create Data Source 19<br />
Figure 9 - ODBC Microsoft Access Setup 19<br />
Figure 10 - ODBC Data Source Administrator 20<br />
Figure 11 - Installing the IntelliTrac X1 21<br />
Figure 12 - Setting parameters for Port Settings in Hyper Terminal 22<br />
Figure 13 - Test Output for X1 on Hyper Terminal 23<br />
Figure 14 - COM Port Setting in X1 Wizard 23<br />
Figure 15 - Enter Unit Password to Reboot in X1 Wizard 24<br />
Figure 16 - Reboot Complete in X1 Wizard 24<br />
Figure 17 - Communications Setting in X1 Wizard 24<br />
Figure 18 - Configuring the X1 to Track using X1 Wizard. 25<br />
Figure 19 - Uploading data into the X1 using X1 Wizard 25<br />
Figure 20 – Signing up for the Google Maps API Key 26<br />
Figure 21 – Google Maps API Key 26<br />
Figure 22 – <strong>GPS</strong> Modem Table Web Page 28<br />
Figure 23 – <strong>Vehicle</strong> Query page prompts <strong>Vehicle</strong> number 29<br />
Figure 24 – <strong>Vehicle</strong> Query page showing the <strong>Vehicle</strong>’s log 29<br />
Figure 25 – <strong>Vehicle</strong> Query page showing the map 30<br />
Figure 26 – Find closest <strong>Vehicle</strong> Page prompting user to enter location 31<br />
Figure 27 – Find closest <strong>Vehicle</strong> Page Map 32<br />
Figure 28 – <strong>Vehicle</strong> Log Page 32<br />
Akila Wajirakumara Page 3
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
Acknowledgements<br />
I would like to thank <strong>my</strong> supervisor, Dr Lim Wee Gin for his undying support, attention <strong>and</strong><br />
his abundance of guidance which helped me throughout this project. He was most<br />
underst<strong>and</strong>ing <strong>and</strong> patient with his supervision over <strong>my</strong> project.<br />
Mr. Ng Kong Leng, the marketing director of “MOBITEK <strong>System</strong> Sdn Bhd” for supplying me<br />
with all the relevant equipments to fulfill <strong>my</strong> project. Also for the training which gave me a<br />
good head start on <strong>my</strong> project, thank you.<br />
And finally to <strong>my</strong> family <strong>and</strong> friends who always believed in <strong>my</strong> abilities <strong>and</strong> potential. My<br />
parents, for all your support <strong>and</strong> love, thank you all.<br />
Akila Wajirakumara Page 4
Abstract<br />
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
This project deals with an <strong>SMS</strong> (Short Message Service) enabled vehicle tracking system.<br />
The heart of this project lies with the use of a <strong>GPS</strong> + GSM modem which is installed in the<br />
vehicle <strong>and</strong> is in charge of tracking the vehicle <strong>and</strong> sending the coordinates to the GSM<br />
(Global <strong>System</strong> for Mobile <strong>com</strong>munication) modem. The GSM modem in the control center<br />
receives the coordinates via <strong>SMS</strong> <strong>and</strong> updates the main database which contains all the<br />
whereabouts of all the vehicles at specified times. The information is uploaded in a website<br />
where the vehicle’s position can be located in a map with the aid of the Google Maps<br />
application. This thesis explores the foundation of <strong>GPS</strong>, GSM, <strong>and</strong> all the software related in<br />
the project; <strong>and</strong> the use of their concepts to produce a vehicle tracking system which is<br />
cheaper <strong>and</strong> more effective than most <strong>com</strong>mercial car tracking features in the market<br />
today.<br />
Akila Wajirakumara Page 5
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
Chapter 1: Introduction<br />
1.1 General Introduction<br />
GSM (Global <strong>System</strong> for Mobile <strong>com</strong>munication) is a cellular network that mobile phones use to<br />
acquire connectivity in their immediate vicinity. These networks operate in different frequency<br />
ranges, mainly between 900 MHz <strong>and</strong> 1800 MHz. It uses a narrowb<strong>and</strong> variation of Time<br />
Division Multiple Access (TDMA), which allows eight simultaneous calls on the same radio<br />
frequency. <strong>SMS</strong> (Short Message Service) is a protocol for sending <strong>and</strong> receiving text messages<br />
over GSM networks. The text can <strong>com</strong>prise of words, numbers or an alphanumeric<br />
<strong>com</strong>bination. A message can go up to 160 characters of text in length using GSM coding.<br />
<strong>GPS</strong> (Global Positioning <strong>System</strong>) is a satellite based navigation system made up of a network of<br />
24 satellites placed into the orbit. These satellites transmit coded information which allows us<br />
to identify locations on earth precisely by measuring the distance from the satellites. The<br />
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> (VTS) also uses <strong>GPS</strong> to take the location, speed, direction <strong>and</strong> time data<br />
via satellite from the Global Positioning <strong>System</strong> to the <strong>GPS</strong> + GSM receiver in a vehicle <strong>and</strong> also<br />
transmits it to a central <strong>com</strong>puter connected to a private network or the internet. It is an<br />
electronic device installed in a vehicle to enable the owner or a third party to track the vehicle’s<br />
location. Most of these systems <strong>com</strong>bine with mobile phones through <strong>SMS</strong> to <strong>com</strong>municate the<br />
vehicle’s location to a remote user. The market for <strong>GPS</strong> vehicle tracking systems is considered<br />
as one of the fastest growing markets for <strong>GPS</strong> applications. There are many levels of<br />
sophistication, but what all systems have in <strong>com</strong>mon is a <strong>GPS</strong> receiver <strong>and</strong> software to put the<br />
tracking results on a map. The <strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> has several applications such as stolen<br />
vehicle recovery, fleet management, asset tracking, field service management, field sales <strong>and</strong><br />
trailer tracking.<br />
PHP (Hypertext Pre-processor) is a server-side; HTML embedded scripting programming<br />
language used to create web pages with dynamic features. In this project it is used for<br />
designing an online <strong>Vehicle</strong> <strong>Tracking</strong> Report.<br />
Akila Wajirakumara Page 6
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
1.2 Aims <strong>and</strong> Objectives<br />
The aim of this project is to produce an <strong>SMS</strong> (Short Message Service) enabled vehicle<br />
tracking system using <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong>. This project is divided into three main parts namely<br />
the <strong>GPS</strong> + GSM modem, the GSM modem <strong>and</strong> the website with the Google Maps<br />
application. My objectives for this project are<br />
1. Install the <strong>GPS</strong> + GSM modem in a vehicle a developing a remote configuration tool.<br />
2. Connecting the GSM modem to the control center <strong>and</strong> ensure it receives the<br />
information sent from the <strong>GPS</strong> + GSM modem.<br />
3. Design an online <strong>Vehicle</strong> <strong>Tracking</strong> Report which includes a map.<br />
Akila Wajirakumara Page 7
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
1.3 The <strong>GPS</strong> + GSM modem<br />
The <strong>GPS</strong> + GSM modem used in this project is the IntelliTrac X1. The modem can function<br />
as a st<strong>and</strong>alone system once programmed using the IntelliTrac X1 Wizard software. The<br />
<strong>GPS</strong> + GSM modem will be the core of this project as it will be used to <strong>SMS</strong> the coordinates<br />
of the vehicle’s location at specified time or distance intervals to the GSM modem in the<br />
control center. There is a SIM card connected to this device.<br />
1.4 GSM modem<br />
Figure 1 - IntelliTrac X1<br />
The GSM modem used in this project is the Q24. This modem is connected to the control<br />
center where it receives <strong>SMS</strong> from the <strong>GPS</strong> + GSM modem <strong>and</strong> is stored in a Microsoft<br />
Access Database with the aid of the <strong>SMS</strong> Engine software. There is a SIM card connected to<br />
this device as well.<br />
Figure 2 - Q24<br />
Akila Wajirakumara Page 8
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
1.5 <strong>System</strong> Architecture diagram<br />
[1]<br />
IntelliTrac X1 (<strong>GPS</strong> Terminal)<br />
Q24 (GSM Modem)<br />
<strong>SMS</strong> Engine<br />
Google Maps Web Application<br />
• Locate the vehicle<br />
• Track the vehicle<br />
• Show <strong>GPS</strong> report<br />
Automatically sends out <strong>GPS</strong> data<br />
through <strong>SMS</strong><br />
Receive the in<strong>com</strong>ing <strong>SMS</strong> <strong>and</strong> insert a<br />
new record to <strong>SMS</strong> Engine<br />
Updates the database <strong>and</strong> uses Google<br />
Maps to locate the vehicle<br />
Akila Wajirakumara Page 9
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
Chapter 2: Literature Review<br />
This thesis covers the basis of a <strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> using <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong>.This chapter<br />
introduces all the theories <strong>and</strong> information related to this project to aid underst<strong>and</strong>ing of the<br />
other chapters in this thesis.<br />
2.1 Programming Languages Required<br />
There are two programming languages, PHP <strong>and</strong> Java Script which are required to develop<br />
the <strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong>. These programming languages are highly essential for this<br />
project in order to interact with the Microsoft Access Databases via ODBC to read the<br />
information <strong>and</strong> to add the Google Maps API Application.<br />
2.1.1 PHP<br />
PHP (Hypertext Pre-Processor) is a widely used general purpose scripting language that is<br />
especially suited for Web development <strong>and</strong> can be embedded into HTML. PHP Scripts are<br />
enclosed within tags (starts with ) <strong>and</strong> because of that, the<br />
programmer has the flexibility to jump between HTML <strong>and</strong> PHP instead of having to rely on<br />
heavy amounts of code to output HTML. Since PHP is executed on the server, the codes<br />
cannot be viewed by clients [11]. In addition, PHP can send HTTP headers, set cookies,<br />
manage authentication <strong>and</strong> redirect users. It offers excellent connectivity to many<br />
databases such as Microsoft Access through ODBC <strong>and</strong> integration with various external<br />
libraries that let you do everything from generating PDF documents to parsing XML [12].<br />
2.1.2 Java Script<br />
Java Script is a scripting language developed by Netscape to enable Web designers to<br />
create interactive websites. Despite the name, Java Script is unrelated to the Java<br />
programming language even though the two of them have superficial similarities; Java<br />
Script was developed independently. Both these languages use syntaxes influenced by that<br />
of C syntax, <strong>and</strong> Java Script copies many Java names <strong>and</strong> naming conventions. It can<br />
interact with HTML enabling Web designers to make their websites more interactive with<br />
dynamic content [13].<br />
Akila Wajirakumara Page 10
2.2 XAMPP<br />
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
XAMPP is an easy to install Apache distribution that contains MySQL, PHP <strong>and</strong> Pearl [4].<br />
Apache is a freely available web server that is distributed under an open source license <strong>and</strong><br />
XAMPP is a free open source cross-platform web server package. It is used as a web<br />
development tool to allow web designers <strong>and</strong> programmers to test their work on their own<br />
<strong>com</strong>puters without any access to the Internet [5]. In this project, we use XAMPP to test our<br />
website in PHP before it is hosted on the World Wide Web.<br />
2.3 Adobe Dreamweaver<br />
Adobe Dreamweaver is an industry st<strong>and</strong>ard website authoring program created by<br />
Macromedia <strong>and</strong> now developed by Adobe <strong>System</strong>s. It enables users to create fullyfunctional<br />
websites using both programming code <strong>and</strong> design view where the user is able to<br />
see the layout of the page. In this project I used Adobe Dreamweaver to do <strong>my</strong> PHP coding.<br />
2.4 ODBC<br />
Open Database Connectivity (ODBC) refers to a software API (Application Programming<br />
Interface) for using Database Management <strong>System</strong>s (DBMS). ODBC is created to be<br />
independent of programming languages or operating systems <strong>and</strong> offers access to different<br />
database systems [6] via SQL queries. It can be used as an access tool to various databases<br />
such as Microsoft Access, Microsoft Excel, Text <strong>and</strong> dBase. Through these Call Level<br />
Interface (CLI) specifications of the SQL Access group, ODBC allows a neutral way if<br />
accessing the data stored in personal <strong>com</strong>puters <strong>and</strong> various databases [7]. ODBC allows us<br />
to grab information from our Microsoft Access Databases <strong>and</strong> insert them into our PHP<br />
codes to be viewed in our website.<br />
2.5 <strong>SMS</strong> Engine<br />
<strong>SMS</strong> Engine is a part of the <strong>SMS</strong> Gateway Development Kit (<strong>SMS</strong> GDK) which is given free<br />
when the GSM modem was purchased. With <strong>SMS</strong> Engine, the <strong>System</strong> Integrator <strong>and</strong><br />
Software Developer (SI/SD) does not need to write any code to write an <strong>SMS</strong> Gateway. It<br />
will read <strong>and</strong> send <strong>SMS</strong>, with the use of a Microsoft Access database it will store the<br />
in<strong>com</strong>ing <strong>SMS</strong> <strong>and</strong> also check if there is any pending <strong>SMS</strong> to be sent. The SI/SD only needs<br />
to insert record into the database to send the <strong>SMS</strong> <strong>and</strong> receive record from the database to<br />
read the <strong>SMS</strong>. The <strong>SMS</strong> Engine takes care of all the <strong>SMS</strong> transactions in this project.<br />
Akila Wajirakumara Page 11
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
2.6 IntelliTrac X1 Wizard<br />
The IntelliTrac X1 Wizard is the software used to program the X1 to send <strong>SMS</strong> of the<br />
coordinates of the vehicle’s location at specified intervals to the GSM modem (Q24). It<br />
records the latitude, longitude, satellite strength, timestamp, heading, altitude, ReportID,<br />
input <strong>and</strong> output at the specific location, coverts <strong>and</strong> <strong>com</strong>presses into an <strong>SMS</strong> <strong>and</strong> sends it.<br />
The IntelliTrac X1 Wizard enables you to program the X1 to send <strong>SMS</strong> at different time or<br />
distance intervals depending on the user’s needs.<br />
2.7 No-IP<br />
No-IP is a Dynamic DNS (Domain Name Service) provider for free services. Dynamic DNS is<br />
a technology that allows the user to update the IP address of a domain in real time. It is<br />
capable of notifying a domain name server to change for networked devices such as routers<br />
or <strong>com</strong>puter systems using the Internet Protocol Suite. The active DNS configuration of its<br />
configured hostnames, addresses or other information are stored in DNS in real time. A<br />
popular Dynamic DNS application is that it provides a residential user’s Internet gateway<br />
that has a variable often changing IP address with a well known hostname resolvable by<br />
network applications through st<strong>and</strong>ard DNS queries [8]. No-IP’s Dynamic DNS applications<br />
allow the user to remotely connect to their <strong>com</strong>puter from work <strong>and</strong> also run a personal<br />
website. Once signed up to the No-IP free service at http://www.no-ip.<strong>com</strong> , it allows the<br />
user to create a domain to use instead of a hard to remember IP address or URL.<br />
Additionally it also uses a dynamic update client to keep track of the user’s dynamic IP<br />
address. Hence the user will always be able to get to their <strong>com</strong>puter even if the user’s IP<br />
address is dynamically assigned [9]. In this project No-IP is used to host the PHP pages <strong>and</strong><br />
the real time updating Microsoft Access databases in the control center into the World Wide<br />
Web.<br />
2.8 Google Maps API<br />
Google Maps is a free web mapping service application <strong>and</strong> technology provided by Google<br />
that powers many map-based Google Maps website, Google Ride Finder <strong>and</strong> embedded<br />
maps on third party websites via Google Maps API (Application Programming Interface). An<br />
API (Application Programming Interface) is a set of routines <strong>and</strong>/or protocols provided by<br />
libraries <strong>and</strong>/or operating system services in order to support the building of the<br />
applications. Google Maps offers street maps, a route planner, <strong>and</strong> an urban business<br />
locator for numerous countries worldwide. Google Earth is a st<strong>and</strong>-alone program for<br />
Microsoft Windows <strong>and</strong> other Operating <strong>System</strong>s which is more sophisticated <strong>and</strong> offers<br />
more globe-viewing features. Google created the Google Maps API to facilitate web<br />
developers to integrate Google Maps into their websites with their own data points. It<br />
embeds Google Maps into your website with Java Script <strong>and</strong> is currently free of charge. The<br />
Google Maps API provides a vast number of utilities for manipulating maps, just like in the<br />
Google Maps website http://maps.google.<strong>com</strong> <strong>and</strong> adds content to the map through a<br />
variety of services. In order to use the Google Maps API, you first need to sign up for an API<br />
key on http://code.google.<strong>com</strong>/apis/maps/signup.html which will then allow you to develop<br />
the map application on your website [1][10].<br />
Akila Wajirakumara Page 12
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
Chapter 3: Getting Started<br />
This chapter covers all the important steps that have to be carried out in order to start<br />
designing the PHP website. The steps are as follows.<br />
Step 1: Create a Microsoft Access Database<br />
Step 2: Configure <strong>and</strong> Test the <strong>SMS</strong> Engine Software<br />
Step 3: Configure the ODBC<br />
Step 4: Install, Test <strong>and</strong> Configure the IntelliTrac X1<br />
Step 5: Adding the Google Maps API<br />
Akila Wajirakumara Page 13
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
3.1 Step 1: Create a Microsoft Access Database<br />
A main Microsoft Access database is created which contains all the information of all the<br />
drivers <strong>and</strong> also a log that contains all the coordinates sent by the IntelliTrac X1 at different<br />
times. The database has two tables, namely the “<strong>GPS</strong>_modem” table which contains<br />
information of all the vehicles that has the X1 device, <strong>and</strong> the “vehicle_log” table that<br />
contains a log of all the coordinates sent by the X1. We shall start off by entering fake<br />
details before connecting the <strong>GPS</strong> + GSM modem <strong>and</strong> the GSM modem.<br />
The fields in the “<strong>GPS</strong>_modem” table are modem_ID, vehicle_no, date_created,<br />
vehicle_type, vehicle_desc <strong>and</strong> #number.<br />
Figure 3 - Table containing all the information of the drivers in the database<br />
Akila Wajirakumara Page 14
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
The fields in the “vehicle_log” table are modem_ID, longitude, latitude, satellite_strength,<br />
timestamp, speed, Heading, Altitude, ReportID, Input an Output.<br />
Figure 4 - <strong>Vehicle</strong> log of all the drivers in the database<br />
Akila Wajirakumara Page 15
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
3.2 Step 2: Configure <strong>and</strong> Test the <strong>SMS</strong> Engine<br />
Software<br />
The Q24 GSM modem is now connected to the control center <strong>and</strong> the <strong>SMS</strong> Engine software<br />
is installed. Firstly it is configured to our requirements <strong>and</strong> the SIM card number is entered.<br />
[1]<br />
Figure 5 - Configuring <strong>SMS</strong> Engine<br />
SIM Setting<br />
SIM Card no: also known as MSISDN<br />
PIN: to unlock SIM operator depending<br />
on the number<br />
Modem<br />
COM: Enter the port number which the GSM Modem<br />
is connected to the PC<br />
Poll: Set how frequent the <strong>SMS</strong> Engine should<br />
access the database. If you set it to 3 seconds, then<br />
the <strong>SMS</strong> Engine will read in<strong>com</strong>ing <strong>SMS</strong>, store into<br />
Inbox <strong>and</strong> query the Outbox to send out <strong>SMS</strong> in every<br />
3 seconds.<br />
Delivery Status Report: If checked, <strong>SMS</strong> Engine will<br />
check for the report for each outgoing <strong>SMS</strong>.<br />
Routing: Check “All” to instruct <strong>SMS</strong> Engine to send<br />
<strong>SMS</strong> to all mobile numbers or checked the<br />
appropriate box to instruct <strong>SMS</strong> Engine to send out<br />
<strong>SMS</strong> selective numbers only. If you set to Maxis<br />
(012), then the <strong>SMS</strong> Engine will only send <strong>SMS</strong> to<br />
mobile numbers starting with 012 only.<br />
Direction: Set the GSM modem to 2 way, 1 way<br />
read only, or 1 way send only. If you set it to 1 way<br />
read, the <strong>SMS</strong> Engine will only read in<strong>com</strong>ing <strong>SMS</strong><br />
<strong>and</strong> will not send out.<br />
Akila Wajirakumara Page 16
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
The settings are then saved <strong>and</strong> then the connection is established by clicking the “Start”<br />
button.<br />
[1]<br />
In<strong>com</strong>ing Message<br />
will increase one if<br />
the <strong>SMS</strong> Engine<br />
receive a message<br />
Sent Message will<br />
increase one if the<br />
<strong>SMS</strong> Engine sent<br />
out a message<br />
Figure 6 - Starting <strong>SMS</strong> Engine<br />
Fail Message will<br />
increase one if the<br />
<strong>SMS</strong> Engine fail to<br />
sent out a message<br />
Akila Wajirakumara Page 17
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
All the received <strong>SMS</strong> is automatically saved in a Microsoft Access Database in the same folder as the<br />
<strong>SMS</strong> Engine software is installed in the hard disk.<br />
Figure 7 - <strong>SMS</strong> Engine Database<br />
The <strong>SMS</strong> Engine can be tested by sending it an <strong>SMS</strong> from a mobile phone. The <strong>SMS</strong> should<br />
be displayed in the <strong>SMS</strong> Engine window as well as in the “Inbox” table in the database.<br />
Akila Wajirakumara Page 18
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
3.3 Step 3: Configure the ODBC<br />
The ODBC has to be configured in order to connect both our databases to our PHP code.<br />
Setting up an ODBC connection is very simple; the steps are as follows.<br />
Go to “Control Panel”, click on “Administrative Tools <strong>and</strong> then click on the “Data Sources<br />
(ODBC)” icon. Open the “<strong>System</strong> DSN” tab <strong>and</strong> click the “Add” button. The following window<br />
will open.<br />
Figure 8 - ODBC Create Data Source<br />
Select “Microsoft Access Driver (*.mdb,*.accdb)” <strong>and</strong> click the “Finish” button.<br />
Figure 9 - ODBC Microsoft Access Setup<br />
Akila Wajirakumara Page 19
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
For the main database type “X1” under “Data Source Name”, then click the “Select” button<br />
<strong>and</strong> browse to the location of the database <strong>and</strong> click “OK”. Repeat the same procedure for<br />
the <strong>SMS</strong> Engine database; name it “<strong>SMS</strong> Engine”.<br />
After <strong>com</strong>pleted, click the “OK” button.<br />
[1]<br />
Figure 10 - ODBC Data Source Administrator<br />
Akila Wajirakumara Page 20
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
3.4 Step 4: Install, Test <strong>and</strong> Configure the<br />
IntelliTrac X1<br />
3.4.1 Installing the IntelliTrac X1<br />
Input/Output Cable<br />
Figure 11 - Installing the IntelliTrac X1<br />
GSM Antenna<br />
RS – 232 Cable<br />
<strong>GPS</strong> Receiver<br />
Akila Wajirakumara Page 21
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
3.4.2 Testing the IntelliTrac X1<br />
In order to test <strong>and</strong> configure the IntelliTrac X1, the Hyper Terminal program is setup to<br />
which the appropriate COM Port is selected which connects the X1 by the RS-232 cable; in<br />
<strong>my</strong> case it is COM6.<br />
The parameters of the Port Settings are then setup as follows<br />
Bits per second: 57600bps<br />
Data bits: 8<br />
Parity: None<br />
Stop bits: 1<br />
Flow control: None<br />
Figure 12 - Setting parameters for Port Settings in Hyper Terminal<br />
Next, click on “Properties” on the toolbar menu, select the “Settings” tab <strong>and</strong> click the<br />
“ASCII Setup” button. Check on the boxes “Send line ends with line feeds” <strong>and</strong> “Echo typed<br />
characters locally” <strong>and</strong> then click “OK”.<br />
Akila Wajirakumara Page 22
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
Back to the main screen, please type the “$ST” then press [Enter], if the <strong>com</strong>munication<br />
has established correctly, the unit should return the message “$ER: =0”as follows.<br />
Figure 13 - Test Output for X1 on Hyper Terminal<br />
If there is no response from the IntelliTrac X1, please check with the serial port connection.<br />
[2]<br />
3.4.3 Configuring the IntelliTrac X1 Wizard<br />
Open the IntelliTrac X1 wizard; select the appropriate COM Port <strong>and</strong> the default Baud Rate<br />
to 57600bps. The incorrect will lead to unavailable <strong>com</strong>munication between the X1 device<br />
<strong>and</strong> the X1 Wizard.<br />
Figure 14 - COM Port Setting in X1 Wizard<br />
Turn ON the power in the IntelliTrac X1 <strong>and</strong> in order to make the connection between the<br />
device <strong>and</strong> the X1 wizard, select “Tool” in the menu bar <strong>and</strong> click on “Reboot”.<br />
It then prompts a password, enter the default password “0000” <strong>and</strong> click “OK”.<br />
Akila Wajirakumara Page 23
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
Figure 15 - Enter Unit Password to Reboot in X1 Wizard<br />
Figure 16 - Reboot Complete in X1 Wizard<br />
Once it has <strong>com</strong>pleted rebooting, next click on the “Communication” icon on the left <strong>and</strong><br />
enter the following settings.<br />
Primary <strong>com</strong>munication type: <strong>SMS</strong><br />
<strong>SMS</strong> base phone number: Enter the phone number of the GSM modem (Q24)<br />
CSD base phone number: Enter the phone number of the <strong>GPS</strong> + GSM modem (X1)<br />
Figure 17 - Communications Setting in X1 Wizard<br />
Go to “File” <strong>and</strong> save it so that this procedure does not have to be carried out the next the<br />
X1 wizard is opened.<br />
Akila Wajirakumara Page 24
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
Next go to Track, select the “Start Function” button configure the X1 to send <strong>SMS</strong> to any<br />
specified interval according to your personal requirements.<br />
Figure 18 - Configuring the X1 to Track using X1 Wizard.<br />
Click on “Backup Battery” on the left <strong>and</strong> select “Turn ON backup battery”. This procedure<br />
can be skipped if there is an alternate method of supplying power to the IntelliTrac X1.<br />
Once all this is done it is now ready to upload all this information to the device. Select<br />
“Tool” from the menu bar <strong>and</strong> click on “Upload”.<br />
Figure 19 - Uploading data into the X1 using X1 Wizard<br />
Remove the Serial cable <strong>and</strong> the power cable; <strong>and</strong> the X1 is ready to be taken for a drive.<br />
[3]<br />
3.5 Step 5: Adding the Google Maps API<br />
Akila Wajirakumara Page 25
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
In Order to use the Google Maps API, we need to sign up for the API Key which is found in<br />
the website http://code.google.<strong>com</strong>/apis/maps/signup.html<br />
Figure 20 – Signing up for the Google Maps API Key<br />
After accepting the terms <strong>and</strong> conditions <strong>and</strong> entering the URL, the Key will be automatically<br />
generated in the next page.<br />
Figure 21 – Google Maps API Key<br />
We are now ready to add the Google Maps API into our website.<br />
Google Maps API Key<br />
Akila Wajirakumara Page 26
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
Chapter 4: Creating the Online <strong>Vehicle</strong> <strong>Tracking</strong><br />
<strong>System</strong><br />
Before the web pages are designed, there is a function that has to be included in the<br />
beginning of every page. This is the function that updates the main database. Whenever the<br />
X1 sends <strong>and</strong> <strong>SMS</strong> to the Q24, the message is automatically saved into the <strong>SMS</strong> Engine<br />
database as a string. <strong>Using</strong> PHP, this message is broken down into ten different fields<br />
namely longitude, latitude, timestamp, speed, satellite strength, heading, altitude,<br />
ReportID, input <strong>and</strong> output. The database is updated with the use of the timestamp. The<br />
timestamp the <strong>GPS</strong> modem gets from the satellite is 8 hours behind. This problem is<br />
rectified using PHP coding <strong>and</strong> the new timestamp is being updated. In order to update the<br />
main database, this new timestamp is converted to seconds. This is done <strong>my</strong> using a simple<br />
algorithm where the timestamp is in the format “yyyy-mm-dd H:m:s”.<br />
Timestamp in seconds = s + (m*60) + (H*60*60) + (dd*24*60*60) +<br />
(mm*30*24*60*60) + (yyyy*365*24*60*60)<br />
This calculation is also done using PHP. Next the latest timestamp in the “vehicle_log” table<br />
in the main database is found <strong>and</strong> is also converted to seconds. The maximum timestamp in<br />
seconds in the main database is then <strong>com</strong>pared with the timestamps in seconds in the <strong>SMS</strong><br />
Engine. A PHP function is created to update the main database if the received phone<br />
number in the <strong>SMS</strong> Engine database matches with the phone numbers in the main database<br />
<strong>and</strong> only if the timestamps in seconds in the <strong>SMS</strong> Engine database are greater than the<br />
maximum timestamp in seconds in the main database. This function is included in every<br />
page in the website.<br />
The Online <strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> website consists of four pages excluding the index<br />
page.<br />
1. View Information of all the <strong>Vehicle</strong>s Page<br />
2. Locate <strong>and</strong> Track <strong>Vehicle</strong>'s last position Page<br />
3. Find Closest <strong>Vehicle</strong> to your location Page<br />
4. View Complete <strong>Vehicle</strong> Log Page<br />
Akila Wajirakumara Page 27
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
4.1 View Information of all the <strong>Vehicle</strong>s Page<br />
This page contains a table of the information of all the drivers that has the IntelliTrac X1.<br />
This is taken from the “<strong>GPS</strong>_modem” table in the main database through ODBC.<br />
Figure 22 – <strong>GPS</strong> Modem Table Web Page<br />
In this page it not only shows the table, it also has links on the <strong>Vehicle</strong> Number to connect<br />
to the page that shows the particular vehicle’s <strong>com</strong>plete log <strong>and</strong> also tracks down its five<br />
latest position on the map.<br />
Akila Wajirakumara Page 28
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
4.2 Locate <strong>and</strong> Track the <strong>Vehicle</strong>’s last position<br />
Page<br />
In this page, the user is prompted to enter their <strong>Vehicle</strong> Number. Once the <strong>Vehicle</strong> Number<br />
is submitted, it will display a table containing the log of the particular <strong>and</strong> also a map with<br />
markers added to the five latest positions.<br />
Figure 23 – <strong>Vehicle</strong> Query page prompts <strong>Vehicle</strong> number<br />
Figure 24 – <strong>Vehicle</strong> Query page showing the <strong>Vehicle</strong>’s log<br />
Akila Wajirakumara Page 29
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
Figure 25 – <strong>Vehicle</strong> Query page showing the map<br />
The balloon shaped marker is the vehicle’s latest position <strong>and</strong> the crossed markers are the<br />
next four positions. The blue lines connecting the markers are called polylines which allows<br />
the user to underst<strong>and</strong> the vehicle’s route more clearly.<br />
Akila Wajirakumara Page 30
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
4.3 Find Closest <strong>Vehicle</strong> to your Location Page<br />
This page allows the user to key in their desired latitude <strong>and</strong> longitude <strong>and</strong> the time period<br />
in hours. Once this information is submitted, it will automatically calculate that distance of<br />
the closest vehicle to the location entered along with its timestamp. It also shows the<br />
position of the vehicle in the map.<br />
Figure 26 – Find closest <strong>Vehicle</strong> Page prompting user to enter location<br />
Figure 27 – Find closest <strong>Vehicle</strong> Page Map<br />
Akila Wajirakumara Page 31
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
When the submit button is clicked after the data is entered, it first creates a table of each<br />
car’s latest timestamp using an SQL statement in the PHP code <strong>and</strong> calculates the distance<br />
between the coordinates <strong>and</strong> that on the table for each car. These timestamps in the table<br />
are converted to seconds in the same manner explained earlier in the thesis. The current<br />
timestamp is created <strong>and</strong> it is also converted to seconds. The number of hours entered by<br />
the users is then converted to seconds <strong>and</strong> is then deducted from the current timestamp in<br />
seconds. A while loop is created which will then eliminate the information of the vehicles in<br />
the table whose timestamp is less than the value calculated earlier. From the vehicles that<br />
are left in the table, the one with the least distance is chosen <strong>and</strong> displayed on the map.<br />
4.4 View Complete <strong>Vehicle</strong> Log Page<br />
This page contains a table of all the <strong>GPS</strong> data received from all the vehicles that has the<br />
IntelliTrac X1. This is taken from the “vehicle_log” table in the main database through<br />
ODBC.<br />
Figure 28 – <strong>Vehicle</strong> Log Page<br />
Akila Wajirakumara Page 32
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
Chapter 5: Conclusion<br />
All the deliverables <strong>and</strong> objectives were <strong>com</strong>pleted. The <strong>GPS</strong> + GSM modem was configured,<br />
tested <strong>and</strong> implemented to track the vehicle’s location <strong>and</strong> displayed on a map with the aid<br />
of Google Maps API in the online <strong>Vehicle</strong> Tacking Report. The IntelliTrac X1 can function as a<br />
st<strong>and</strong>alone system once the embedded application is transferred into it. The Q24 can<br />
successfully receive all the <strong>GPS</strong> data sent by the IntelliTrac through without any delay<br />
provided there is GSM connectivity in the location of the two parties, the <strong>GPS</strong> + GSM<br />
modem <strong>and</strong> the GSM modem. The control center can automatically update the main<br />
database each time <strong>GPS</strong> data is received. The online <strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> is able to<br />
locate, track <strong>and</strong> calculate the distance of the closest vehicle available to a desired location<br />
at any period of time. These equipments <strong>and</strong> data can only help to a certain extent because<br />
practical <strong>com</strong>prehension is more challenging <strong>and</strong> requires greater analysis with <strong>com</strong>parison<br />
to hypothetical underst<strong>and</strong>ings. This project has vastly broadened <strong>my</strong> knowledge about the<br />
theory of <strong>GPS</strong> <strong>and</strong> also improved <strong>my</strong> programming skills in PHP. During the course of<br />
<strong>com</strong>pleting the project, there were many expediency issues which were added to ensure<br />
that the product realization is <strong>com</strong>plete, robust <strong>and</strong> usable for <strong>com</strong>mercialization of this<br />
system.<br />
5.1 Important features of this project<br />
1. <strong>GPS</strong> + GSM modem can send <strong>GPS</strong> data to the GSM modem via <strong>SMS</strong> at user<br />
desired intervals of time <strong>and</strong>/or distance.<br />
2. Ability to track a vehicle’s last five positions <strong>and</strong> displayed on a map with<br />
different markers clearly distinguishing their time <strong>and</strong> location.<br />
3. Polylines on the map when tracking a vehicle. Polylines are imaginary lines<br />
connecting the five latest positions in order of time giving a higher approximation<br />
of the vehicle’s route.<br />
4. Finding <strong>and</strong> calculating the distance of the nearest vehicle to a specific location<br />
entered by the user at given period of time.<br />
Akila Wajirakumara Page 33
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
5.2 Practical Implementations<br />
The Online <strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> can be used in many places like buses, taxis <strong>and</strong> other<br />
transporting <strong>com</strong>panies. The following are a few scenarios where the <strong>Vehicle</strong> <strong>Tracking</strong><br />
<strong>System</strong> can be really helpful.<br />
• Fleet Management: When managing a fleet of vehicles, with the ability of finding the<br />
real-time location of all drivers would allow the management to meet the customer<br />
need in a more effective manner. Drivers would only need an internet connection to<br />
track <strong>and</strong> dispatch the vehicle e.g. Boss said, "I want to know which lorry is closest<br />
to the pick-up point so that I can call that nearest lorry to pick-up the goods”.<br />
• Asset <strong>Tracking</strong>: If a <strong>com</strong>pany needs to track valuable assets for monitoring <strong>and</strong> other<br />
purposes, it could closely monitor its movement <strong>and</strong> status on the map.<br />
• Field Service Management: Companies with a service workforce for services must be<br />
able to plan the workers’ time, scheduled subsequent customer visits <strong>and</strong> be able to<br />
operate efficiently. With vehicle tracking, it allows the <strong>com</strong>panies to quickly locate a<br />
field engineer <strong>and</strong> dispatch the closest one to meet a new customer request.<br />
5.3 Future Development<br />
The potential of this project can be further explores <strong>and</strong> improved to its functionality <strong>and</strong><br />
features. The GSM can also send <strong>SMS</strong>, but this hasn’t been used in this project. This can<br />
open doors to lot improvements for the <strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> in the <strong>com</strong>mercial world. A<br />
program can be made where an <strong>SMS</strong> can be sent from the control center to driver’s mobile<br />
phone giving him the location of his next destination. An Immobilizer could be connected to<br />
the X1 which can be programmed to function through <strong>SMS</strong> where the control center could<br />
trigger the immobilizer if the driver is violating orders such as speeding or going out of<br />
track.<br />
The IntelliTrac X1 has an RF (Radio Frequency) reader output which can be implemented in<br />
a school bus for example. In this case, each student would have their own RFID cards <strong>and</strong><br />
once a student enters the bus the student’s details can be recorded along with the <strong>GPS</strong><br />
location when the student entered <strong>and</strong> left. The control center can monitor the student’s<br />
attendance <strong>and</strong> where they entered <strong>and</strong> left the bus.<br />
Akila Wajirakumara Page 34
References<br />
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
[1] <strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> Guide provided by MOBITEK Sdn Bhd.<br />
[2] IntelliTrac X1 Installation Guide provided by MOBITEK Sdn Bhd.<br />
[3] X1 Wizard User Manual provided by MOBITEK Sdn Bhd.<br />
[4] http://www.apachefriends.org/en/xampp.html<br />
[5] http://en.wikipedia.org/wiki/XAMPP#Use<br />
[6] http://www.ntchosting.<strong>com</strong>/postgresql/odbc-jdbc-with-php-perl-<strong>and</strong>-python.html<br />
[7] http://www.tech-faq.<strong>com</strong>/odbc.shtml<br />
[8] http://en.wikipedia.org/wiki/Dynamic_DNS<br />
[9] http://www.no-ip.<strong>com</strong>/services/managed_dns/free_dynamic_dns.html<br />
[10] http://www.google.<strong>com</strong>/enterprise/maps/<br />
[11] http://www.webopedia.<strong>com</strong>/TERM/P/PHP.html<br />
[12] http://articles.techrepublic.<strong>com</strong>.<strong>com</strong>/5100-22_11-5074693.html<br />
[13] http://www.webopedia.<strong>com</strong>/TERM/J/JavaScript.html<br />
Akila Wajirakumara Page 35
Appendix<br />
Codes<br />
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
Google Maps codes to Locate <strong>and</strong> Track <strong>Vehicle</strong><br />
<br />
Find Closest <strong>Vehicle</strong><br />
<br />
<br />
var UnitID="";<br />
var datetime="";<br />
var lat="";<br />
var long="";<br />
var datetime1="";<br />
var lat1="";<br />
var long1="";<br />
var datetime2="";<br />
var lat2="";<br />
var long2="";<br />
var datetime3="";<br />
var lat3="";<br />
var long3="";<br />
var datetime4="";<br />
var lat4="";<br />
var long4="";<br />
function loadEarth() {<br />
if (GBrowserIsCompatible()) {<br />
var point;<br />
var cIcon = new GIcon();<br />
cIcon.image = 'cross.png';<br />
Akila Wajirakumara Page 36
cIcon.iconSize = new GSize(25,25);<br />
cIcon.iconAnchor = new GPoint(16,11);<br />
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
var map=new GMap2(document.getElementById("map"));<br />
map.addControl(new GOverviewMapControl());<br />
map.enableDoubleClickZoom();<br />
map.enableScrollWheelZoom();<br />
map.addControl(new GMapTypeControl());<br />
map.addControl(new GSmallMapControl());<br />
var marker = new GMarker(new GLatLng(lat,long));<br />
var marker1 = new GMarker(new GLatLng(lat1,long1),cIcon);<br />
var marker2 = new GMarker(new GLatLng(lat2,long2),cIcon);<br />
var marker3 = new GMarker(new GLatLng(lat3,long3),cIcon);<br />
var marker4 = new GMarker(new GLatLng(lat4,long4),cIcon);<br />
map.setCenter(new GLatLng(lat,long),17);<br />
GEvent.addListener(marker, "click", function() {<br />
map.openInfoWindowHtml(map.getCenter(),("<strong>Vehicle</strong> No: " + UnitID + "" + "DateTime:<br />
" + datetime + "" + "Longitude:" + long + "" + "Latitude:" + lat +<br />
""));<br />
});<br />
GEvent.addListener(marker1, "click", function() {<br />
map.openInfoWindowHtml(map.getCenter(),("<strong>Vehicle</strong> No: " + UnitID + "" + "DateTime:<br />
" + datetime1 + "" + "Longitude:" + long1 + "" + "Latitude:" + lat1 +<br />
""));<br />
});<br />
GEvent.addListener(marker2, "click", function() {<br />
map.openInfoWindowHtml(map.getCenter(),("<strong>Vehicle</strong> No: " + UnitID + "" + "DateTime:<br />
" + datetime2 + "" + "Longitude:" + long2 + "" + "Latitude:" + lat2 +<br />
""));<br />
});<br />
GEvent.addListener(marker3, "click", function() {<br />
map.openInfoWindowHtml(map.getCenter(),("<strong>Vehicle</strong> No: " + UnitID + "" + "DateTime:<br />
" + datetime3 + "" + "Longitude:" + long3 + "" + "Latitude:" + lat3 +<br />
""));<br />
});<br />
GEvent.addListener(marker4, "click", function() {<br />
map.openInfoWindowHtml(map.getCenter(),("<strong>Vehicle</strong> No: " + UnitID + "" + "DateTime:<br />
" + datetime4 + "" + "Longitude:" + long4 + "" + "Latitude:" + lat4 +<br />
""));<br />
});<br />
Akila Wajirakumara Page 37
}<br />
map.addOverlay(marker);<br />
map.addOverlay(marker1);<br />
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
map.addOverlay(marker2);<br />
map.addOverlay(marker3);<br />
map.addOverlay(marker4);<br />
map.setCenter(new GLatLng(lat,long), 16);<br />
map.setMapType(G_SATELLITE_MAP);<br />
var polyline = new GPolyline([<br />
new GLatLng(lat, long),<br />
new GLatLng(lat1, long1),<br />
new GLatLng( lat2, long2),<br />
}<br />
<br />
new GLatLng(lat3, long3),<br />
new GLatLng(lat4, long4)<br />
], "#3333cc", 10);<br />
map.addOverlay(polyline);<br />
<br />
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
Functions for Updating the Main Database<br />
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
}<br />
else if ($gpsday==31)<br />
{<br />
}<br />
case "02":<br />
break;<br />
$gpsmnth = "02";<br />
$gpsday = "01";<br />
if ($gpsyr%4 ==0)<br />
{<br />
}<br />
else<br />
{<br />
if ($gpsday9 && $gpsday
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
}<br />
case "03":<br />
break;<br />
}<br />
$gpsday = $gpsday + 1;<br />
else if ($gpsday==28)<br />
{<br />
}<br />
if ($gpsday9 && $gpsday
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
}<br />
else if ($gpsday==30)<br />
{<br />
}<br />
case "05":<br />
break;<br />
if ($gpsday9 && $gpsday
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
{<br />
}<br />
case "07":<br />
break;<br />
if ($gpsday9 && $gpsday
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
}<br />
case "09":<br />
break;<br />
if ($gpsday9 && $gpsday
case "11":<br />
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
break;<br />
if ($gpsday9 && $gpsday
}<br />
else<br />
{<br />
}<br />
}<br />
$gpshr = $gpshr;<br />
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
$gpsts = "$gpsyr-$gpsmnth-$gpsday $gpshr:$gpsmin:$gpssec";<br />
$gpstss = $gpssec + ($gpsmin * 60) + ($gpshr * 60 * 60) + ($gpsday * 24 * 60 * 60) + ($gpsmnth *<br />
30 * 24 * 60 * 60) + ($gpsyr * 365 * 24 * 60 * 60);<br />
return $gpstss;<br />
}<br />
function gps_to_timestamp($gpst)<br />
{<br />
$gpsyr = substr($gpst, 0, 4);<br />
$gpsmnth= substr($gpst, 4, 2);<br />
$gpsday = substr($gpst, 6, 2);<br />
$gpshr = substr($gpst, 8, 2);<br />
$gpsmin = substr($gpst, 10, 2);<br />
$gpssec = substr($gpst, 12, 2);<br />
$gpshr = $gpshr + 8;<br />
if ($gpshr=24)<br />
{<br />
$gpshr = $gpshr - 24;<br />
if ($gpshr
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
{<br />
}<br />
$gpsday = $gpsday + 1;<br />
$gpsday = "0$gpsday";<br />
else if ($gpsday>9 && $gpsday
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
}<br />
case "03":<br />
break;<br />
if ($gpsday9 && $gpsday
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
{<br />
}<br />
$gpsday = $gpsday + 1;<br />
$gpsday = "0$gpsday";<br />
else if ($gpsday>9 && $gpsday
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
}<br />
$gpsday = "0$gpsday";<br />
else if ($gpsday>9 && $gpsday
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
else if ($gpsday>9 && $gpsday
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
}<br />
$gpsday = $gpsday + 1;<br />
else if ($gpsday==31)<br />
{<br />
}<br />
case "11":<br />
break;<br />
if ($gpsday9 && $gpsday
}<br />
else<br />
{<br />
}<br />
}<br />
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
else if ($gpsday==31)<br />
{<br />
}<br />
$gpshr = $gpshr;<br />
break;<br />
$gpsmnth = "01";<br />
$gpsday = "01";<br />
$gpsyr = $gpsyr + 1;<br />
$gpsts = "$gpsyr-$gpsmnth-$gpsday $gpshr:$gpsmin:$gpssec";<br />
return $gpsts;<br />
}<br />
function timestamp_to_second($ts)<br />
{<br />
$yyyy= substr($ts, 0, 4);<br />
$mm= substr($ts, 5, 2);<br />
$dd= substr($ts, 8,2);<br />
$hr= substr($ts, 11, 2);<br />
$min= substr($ts, 14,2);<br />
$sec= substr($ts,17, 2);<br />
$tss = $sec + ($min * 60) + ($hr * 60 * 60) + ($dd * 24 * 60 * 60) + ($mm * 30 * 24 * 60<br />
* 60) + ($yyyy * 365 * 24 * 60 * 60);<br />
}<br />
return $tss;<br />
function<br />
add_log_entry($modem_id,$longitude,$latitude,$sattelite_str,$timestamp,$speed,$heading,$altitude,<br />
$report_id,$input,$output)<br />
{<br />
$query = "INSERT INTO<br />
vehicle_log(modem_ID,longitude,latitude,sattelite_strength,[timestamp],speed,Heading,Altitude,Rep<br />
ortID,Input,Output)<br />
values<br />
Akila Wajirakumara Page 53
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
('$modem_id','$longitude','$latitude','$sattelite_str','$timestamp','$speed','$heading','$altitud<br />
e','$report_id','$input','$output')";<br />
$dbc = odbc_connect("X1","",""); // Trying to establish connection with database<br />
if (!$dbc)<br />
{<br />
exit("Connection failed:".$dbc);<br />
}<br />
$rs = odbc_exec($dbc,$query);<br />
odbc_close($dbc);<br />
}<br />
function get_modem_id_for_number($number)<br />
{<br />
$query = "SELECT modem_ID FROM <strong>GPS</strong>_modem WHERE `#number` = '$number'";<br />
$dbc = odbc_connect("X1","",""); // Trying to establish connection with database<br />
if (!$dbc)<br />
{<br />
exit("Connection failed:".$dbc);<br />
}<br />
$rs = odbc_exec($dbc,$query);<br />
if (!$rs)<br />
{<br />
exit("Error in SQL. ".$rs);<br />
}<br />
$result = odbc_result($rs,1);<br />
return $result;<br />
odbc_close($dbc);<br />
}<br />
function get_latest_timestamp_in_db()<br />
{<br />
$dbc = odbc_connect("X1","",""); // Trying to establish connection with database<br />
if (!$dbc)<br />
{<br />
exit("Connection failed:".$dbc);<br />
}<br />
Akila Wajirakumara Page 54
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
$query = "SELECT TOP 1 timestamp FROM vehicle_log order by timestamp desc"; // SQL<br />
Statement<br />
$rs = odbc_exec($dbc,$query);<br />
if (!$rs)<br />
{<br />
exit("Error in SQL. ".$rs);<br />
}<br />
while (odbc_fetch_row($rs))<br />
{<br />
}<br />
$ts = odbc_result($rs, "timestamp");<br />
$yyyy= substr($ts, 0, 4);<br />
$mm= substr($ts, 5, 2);<br />
$dd= substr($ts, 8,2);<br />
$hr= substr($ts, 11, 2);<br />
$min= substr($ts, 14,2);<br />
$sec= substr($ts,17, 2);<br />
$tss = $sec + ($min * 60) + ($hr * 60 * 60) + ($dd * 24 * 60 * 60) + ($mm * 30 * 24 * 60<br />
* 60) + ($yyyy * 365 * 24 * 60 * 60);<br />
return $tss;<br />
odbc_close($dbc);<br />
}<br />
function get_message_<strong>and</strong>_number()<br />
{<br />
$dbc = odbc_connect("<strong>SMS</strong>Engine","",""); // Trying to establish connection with database<br />
if (!$dbc)<br />
{<br />
exit("Connection failed:".$dbc);<br />
}<br />
$query = "SELECT message,mobile FROMInbox";<br />
$rs = odbc_exec($dbc,$query);<br />
$i=1;<br />
while (odbc_fetch_row($rs))<br />
{<br />
$message = odbc_result($rs, "Message");<br />
Akila Wajirakumara Page 55
}<br />
<strong>Vehicle</strong> <strong>Tracking</strong> <strong>System</strong> <strong>Using</strong> <strong>GPS</strong> <strong>and</strong> <strong>SMS</strong><br />
$mobile = odbc_result($rs, "Mobile");<br />
$message_exploded = explode(',',$message);<br />
for($j=0;$j<br />
Akila Wajirakumara Page 56