S14: Location Tracker

From Embedded Systems Learning Academy
Revision as of 23:42, 6 August 2014 by Preet (talk | contribs) (Project Source Code)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Location Tracker

Abstract

The location tracker is designed to help you keep on eye on where someone—like your kid—is. An Android application communicates with the locator beacon to determine the location of the target and how to get there.

Objectives & Introduction

Two nodes shall be designed to communicate over GPRS/GSM network. Node Android requests data from node target. The Android application pinpoints the target and finds the fastest path to the target based on the received location. A SMS message is sent by the app to trigger the beacon to start sending its coordinates back. A GPRS/GSM module controlled by the SJ One Board on the beacon receives the SMS message, and triggers a new GPS coordinate reading from a GPS module. The GPS coordinates are sent back periodically through SMS messages for the app to map.


The project required the following objectives to be accomplished:

  • Read GPS coordinates from GPS module
  • Receive and send SMS messages from GPRS/GSM module
  • Send and receive SMS messages from within Android app
  • Map location of Android phone and target
  • Retrieve and draw driving/walking path from source to target

Team Members & Responsibilities

  • Arpit Amin
    • GPS: Communication and data parsing
  • Caleb Chow
    • Android application: SMS message handling, Google Maps API, and UI
  • Sin Yu Ho
    • SMS: Multitasking design to handle SIM900 and GPS modules
  • Abraham Ruiz
    • Android application: Source to destination path algorithms and Google Maps API

Schedule

Week# Date Task Actual
1 3/6
  • System design
  • Order parts
  • Ordered GSM/GPRS module
  • Obtained GPS module from previous project
2 3/13
  • Android app UI design
  • Decided UI requirements
3 3/20
  • Interface GPS module
  • Parse GPS coordinates
  • Test GPS parsing
  • Begin interfacing GPS and GSM/GPRS modules
4 3/27
  • Interface GSM/GPRS module
  • Test sending SMS messages
  • GPS data parsing complete
5 4/3
  • Make Android app recognize and parse SMS message
  • SJ One board sends SMS messages
  • Begin work on Android app
6 4/10
  • Integrate Google Map into app
  • Continue trying to get app to send and receive SMS
7 4/17
  • Improve app UI
  • Testing
  • Android app sends and receive SMS messages
  • Locations are displayed on map
8 4/24
  • Testing indoor and outdoor
  • Find recommendations for future improvement
  • Integrate GPS portion with SMS portion
9 5/1
  • Final touches
  • Package locator module
10 5/8
  • Finish report
  • Add path between self and target
11 5/15
  • Prepare for demo
  • Finish report
  • Demo

Parts List & Cost

Part Name and Link Price
SIM900 GPRS/GSM module $48
Ublox NEO-6M GPS Module $23
EasyAcc USB Power Bank DC 5V 2.1A, Output $23
Mini SIM card $20 ($10 card + $10 T-Mobile prepaid service)
SJ One Board $80
Total $194

Design & Implementation

Hardware Design

The Android app communicates with the SJ One board using the GSM network. Since the SJ One Board does not have an integrated GSM module, the SIM900 module was chosen to provide communication between the Android App and the SJ One Board. The SIM900 was interfaced to the SJ One Board via UART. A GPS module is required to connect with satellites to provide a triangulation area for the SJ One Board; Moreover, this GPS module must provide latitude and longitude data as fast as possible. It must also contain a footprint (including antenna). For this reason, we choose the Ublox NEO-6M GPS Module. This module weights 0.63 oz with the following dimensions: 1.22 in. x 0.91 in. x 0.16 in. (L X W X H). This GPS module was interfaced to the SJ One Board via UART. This module have four pin named power vcc, Ground gnd, transmitter tx and receiver rx. This module default baud rate is 9600 bps. This module can be programmed for different baud rate depending on requirement. Figure 1 shows the block diagram for this project and Figure 2 shows the locator beacon components.

Figure 1. System Block Diagram


Figure 2. Locator Beacon

Hardware Interface

The GPS module communicates using UART. The following table shows the hardware interface between the GPS module and SJ One board:

SJ One Board GPS Module

VCC(3.3V)

VCC (P1)

Ground (GND)

Ground (P4)

UART2 RX (P2.9)

UART TX (P3)

The SIM900 GPRS/GMS module also communicates using UART. The following table shows the pin connections:

SJ One Board SIM900 GPRS/GSM Module External 5V Power Bank

VCC (P2)

5V

Ground (GND)

Ground (P1)

Ground

UART3 RX (P4.29)

UART TX (P3)

UART3 TX (P4.28)

UART RX (P4)

GPIO Output (P2.0)

Power (P5)

GPIO Output (P2.1)

Reset (P6)

Since the SIM900 and the GPS modules communicate via UART, There is only one device driver required for the SJ One Board: UART. UART 2 and UART3 drivers were reused from the provided base project.

Figure 3 shows a schematic containing the pin connections of the GPS and GPRS/GSM module.

Figure 3. Locator Beacon Schematic

Software Design and Implementation

Locator Beacon

The locator beacon is composed of four parts: a SJ One board, GPS and GPRS/GSM modules, and 5V 2.1A battery pack. On the SJ One board, the processor communicates with GPS and GPRS modules. Both modules have their own task. The following explains the features of each task and introduces a few main functions.

  1. GPS Task - GPS task gets the data from the GPS module and parses the GPS data. The data is retrieved from the module in NMEA format. With the use of some computations, this NMEA format can be used to find coordinates that can be used by Google Maps. UART2 on the SJ One board is initialized at a baud rate of 9600 bps to communicate with the GPS module.
    1. init() - This task get the UART instance and initialize the UART bus at 9600 bps for GPS module to transmit the NMEA Data
    2. run()- As GPS output various lines of data, this task checks if the data is available or not. Then it locates the line that start with “$GPGLL”, as this line contains all the usefull data for this project. The second segment on this line is the latitude in NMEA format, and third segment is the direction N or S, indicating northern or southern hemisphere. In the same way, the fourth segment is longitude and fifth is E or W, indicating Eastern or Western. This task takes the NMEA format longitude and multiplies it with -1 if it indicates E, and multiplies latitude with -1 if it indicate S
    3. calculate()- This function take the value from the run task and converts the NMEA data to the coordinates value so that Google Maps can understand the coordinates and display the location on the maps

Figure 4 shows the flowchart for the GPS task.

Figure 4. GPS Task Flowchart
  1. GPRS/GSM Task - This task manages receiving and sending SMS messages. It sends a signal to the GPS task to obtain the current location, which is passed between the tasks using a queue. To communicate with GPRS module, UART 3 is used and its baud rate is set to 115200 bps. Then, the GPRS module is confirmed to be on by setting AT commands and getting a response. If GPRS module is not on, a reset signal and power signal are sent from SJSU One board.Then, SJSU One board turn off GPRS echo feature, and also setup the sending and receiving feature.
    1. init() - set baud rate, create binary semaphore and a queue to store message
    2. taskEntry() - Check if GPRS module is on, turn off the echo, set receive and send message format
    3. run() - This schedules SMS send and receive activities
    4. checkNetworkRegAndSendSMS() - This checks if the SIM card is registered with the Network. If it is, call pass the number and message to sendSMS(). If there is no message in the message queue, it sends a semaphore to GPS module to obtain a new coordinate
    5. sendSms(const char * number, char * message) - This gets the phone number and message and build a AT command and send it to GPRS module
    6. recvSms() - This checks the received buffer in GPRS if there is any message is arrived. If there is, go to readSMS()
    7. readSms(char * recvStr, int ) - This obtains the whole message from received buffer and uses smsDecoder() to get sender number and sender request. Then send it to userRequest
    8. userRequest(char *senderNum, char * msg) - This checks the phone number with the authorized phone number. If it is an authorized phone number, it starts sending SMS or stop sending SMS according to the request

Figure 5 shows the flowchart for the GPRS task.

Figure 5. GPRS Task Flowchart


Figure 6 shows the local variable that are used.

Figure 6. GPRS Task Local Variables

The local variable, gprs, is a pointer to uart to communicate with SIM900 module. The smsSendMsg_f is to indicate if the SMS should keep sending or not, and countDisplay is the number that is display on LED on SJ One board to indicate number of SMS is sent.

Android App

There are three main components/Java files in the Android application:

  1. MessagingReceiver
    • This module is started when android app starts (from AndroidManifest)
    • It knows when system receives an SMS message and passes the event to the MessagingService
  2. MessagingService
    • This module retrieves the source and body of the SMS message from the event received
    • The source phone number is validated based on the phone number set in the user settings
    • Once validated, the body is validated and parsed to get the GPS coordinates
    • The coordinates are passed to the MainActivity to be displayed
  3. MainActivity
    • This module contains the UI for the app
    • The device location is displayed when the app is started and continually updated
    • Once a valid destination location is received, the location is displayed
    • It chooses between walking path mode or driving path mode based on distance to the destination
    • The fastest route to the destination is retrieved using the API from the Google Direction and Place library
    • A button is used to start and stop receiving GPS coordinates
    • A settings page can be accessed to configure the target name and phone number

Please note that in order to use Google Maps API v2. you need to get the an Android certificate and the Google Maps API key. Directions on how to get this credential can be found here.

Figure 7 shows the software architecture diagram of the Location Tracker android app.

Figure 7. Software Architecture Diagram for the Location Tracker App

Testing & Technical Challenges

Android App

In order to test this system. One student started to run the Android App from Campbell, CA and another student started to run the SJ One board from Sunnyvale. Clearly, the distance between the two student is more than 200 yards. Therefore, the Android will draw the Driving fastest route. When the user presses the “update” button, he/she will receive sms with the current latitude and longitude of the target. These message will never stop unless the user presses the “stop” button. Figure 9 shows the screenshot of the app after pressing the update button; note that the app shows a path using freeway to the destination, and it prints its Latitude and Longitude. To protect the home location of our student, we “blind” the location of the destination. Figure 10 shows the screenshot of the app after pressing the stop button. This test shows that the android app is communicating with the SJ One Board using the GSM network and the SIM900 module. In addition, this test shows that the SJ One Board is communicating with the GPS module by requesting coordinate data.

Figure 8. App Home Screen


Figure 9. App Updating


Figure 10. App Stopped Updating


Figure 11. App Walking Path


Figure 12. App Settings

Please note that if you do not press the “stop” button, the SJ One Board will continuously send sms to the android app. Therefore, surcharge will apply by your cell phone carrier.

Fastest Walking/Driving Path

One of the technical challenge in this project was to find the fastest driving in the android app. Google Maps Android API v2 does not provide any API to draw a path between the source and destination; as a result, the Google Direction and Place library was used. This library is not included in the Android source code, so the documentation is vague.

Locator Beacon

SMS Messaging

This part of the project requires to send and receive SMS message. One of the technical challenge is the GSM network. During this development, a prepaid card is used. A prepaid card is required to activate daily by a normal cell phone. Also, the received buffer in SIM900 module can only store sender information and the first character in SMS message body. Therefore, the locator beacon receives one character ‘Y’ to start sending latitude and longitude data, or character ‘N’ to stop sending coordinate.

GPS

After interfacing the GPS module with SJOne board the data received from the module was zero for both latitude and longitude. As the GPS module schematics showed different baud rate, we tried all the baud rate to check on which baud rate the data is received. After testing multiple time we decided to test in open field. In open field we started getting data at 9600 bps. The problem we faced here was that this GPS module was not for indoor usage. If the building is made of concrete and iron, then this GPS module won’t receive any data. For this GPS module, we had to be outside the building all the time since this GPS module was specifically designed for RC airplanes.

Conclusion

The Location Tracker is designed to keep track of where someone or something is. It brings together a microcontroller, GPS module, GPRS/GSM module, and Android phone to create a system capable of helping locate an object. The main objective of this project was to allow an Android phone to receive GPS coordinates of the object being tracked. This was accomplished by using a microcontroller to read GPS coordinates and sending the coordinates to the phone through SMS messages. The main challenge of the project was in the SMS handling at the microcontroller. SMS messages were sent and received by carefully following the steps defined by the SIM900 AT command manual.

Overall, this project taught how to divide a project into smaller components so that the components could be integrated later. Communication and synchronization between the tasks in FreeRTOS was also practiced. Information had to be passed between FreeRTOS tasks and sent to the Android app, which then had to be processed and displayed in a manner that is useful to the user. A map with the path to the object, along with the timestamp, distance, and name were displayed such that the user of the app could track and locate the object.

Project Video

TODO

Project Source Code

References

Acknowledgement

We would like to thank Preet for teaching us about different serial communication protocols, how to write drivers, and about FreeRTOS.

References Used

Android Developer: [1]

SJ One Board: [2]

SIM900 AT Command Manual [3]

Google Direction and Place Library [4]