본문 바로가기

Hacked Brain/hackgadget.com

GPS 휴대폰에 구글맵 사용하기. Using Google Maps with a Mobile GPS Tracker

Two weeks ago I posted about how to interface an AVR microcontroller to a Telit GM862. You can read it here: Interfacing an AVR controller to a GPS Mobile Phone.
That post got listed on Hack-A-Day, Engadet and Makezine among many others! w00t! Thanks for posting and reading it, I really appreciate it.

source : http://tinkerlog.com/

This post will show you, how to use this equipement to send an SMS with your current position and how to display it in Google Maps.

사용자 삽입 이미지

How does it work?

The controllers serial port is attached to the serial port of the GM862 module. This way the controller is able to send AT commands to the module and receive responses. The GM862 has two serial ports, one for controlling the modem, the other for receiving GPS data in NMEA 0183 format. Fortunately we can access the GPS through the modem port, what saves us from using a second serial port.

To be able to debug and control the controller, I use a second serial port, that connects the controller to my PC. That way I am able to send commands to the controller and steer the program flow as long as it is not fully tested and completed. The following steps are needed to get it up and running.

  • Power on the circuit.
  • Power on the GM862 module (done by the ATmega8)
  • Initialize the modem.
  • Initialize the GPS module (may be omitted).
  • Request a GPS position (repeat until the position is fix).
  • Send an SMS with GPS position to an SMS-to-Email service.
  • Open your email and click the Google Maps link.

More details

As the ATmega8 has only one hardware UART, I use this to communicate with the modem at 19200 baud. For debugging purpose, the second serial port is implemented with a software UART with communicates with the PC with 9600 baud.

Starting the controller gives the following menu on the terminal:

------
Beacon v0.02 2007/07/28
s - Change sms phone number
o - Switch modem on/off
i - Init modem
m - Send SMS
c - Cold start GPS
p - Request GPS
------
key >

Switching the modem on and off is done by pulling the pin 17 of the GM862 to low for at least a second. The status LED of the modem should start to blink in response.

Initializing the modem is done with the following sequence of AT commands:

  • AT, say hello
  • AT+IPR=19200, set the baud rate to 19200
  • AT+CPIN=<pin>, set your PIN for the SIM card
  • AT+CMEE=2, choose extended error messages

The modem should respond with the status LED blinking slower, if the PIN matches and the network is reachable.

Initializing the GPS is optional, as the modul starts the GPS on power on. You can force a cold or a warm start.

  • AT$GPSR=1, issue a cold start
  • AT$GPSR=2, issue a warm start

If you ommit the cold or warm start, you should be able to see a fixed position within 30 seconds after you powered up the module. This time may vary with your position and the reachability of the satellites.

The current position is requested by sending

  • AT$GPSACP, read the acquired position

The response contains information about current time and date, the position and the number of available satellites.

To send send an SMS, send the following commands:

  • AT+CMGF=1, select text sms format
  • AT+CMGS="<phone number>", send the message to the given phone number. This command responds with an prompt >. Now the text of the SMS can be transmitted. The message has to end with 0x1A.

Parsing the GPS position

The position string received from the GPS looks like this:

GPSACP: 131924.999,5343.9291N,00954.7841E,2.6,34.0,3,29.78,0.32,0.17,
130707,07

All tokens are separated with comma. The tokens are:

  • time, hhmmss.SSS
  • position, latitude, degrees and minutes
  • position, longitude, degrees and minutes
  • hdop, horizontal diluition of precision
  • position, altitute, meters
  • fix, 0=invalid, 2=2D, 3=3D
  • cog, course over ground
  • spkm, speed in km
  • spkn, speed in knots
  • date, ddmmyy
  • nsat, number of satellites

The position data received is not directly usable for Google Maps, because the GPS returns degrees and minutes, but GM wants degress as a floating point number. That means the minutes have to be converted to decimal fraction of degrees.

Sending a Google Maps link

Now that we have received and converted the GPS position, we are ready to send an SMS with a link to GM. The link has the following format:

http://maps.google.com/maps?q=<lat>,<lon>%28<message>
%29&t=k&z=<zoom>

You can embed a message, which appears in the popup box. It is surrounded by encoded brackets. Further you can control the zoom factor and the type of map (k=satellite, m=map).
Now this link has to be send as an SMS to an SMS-to-email service that forwards the SMS as email to the given address.

사용자 삽입 이미지

Conclusion

If everything went well, you should be able to click the link and see your browser opening Google Maps with your position.

사용자 삽입 이미지

Next todos are pollishing the code to be able to show it and having it more self-sufficient. Send me an email or comment, if you would like to see it online.

Links