After having built the hardware in Part 1, it is fairly useless without a way to get the GPS data from the device somewhere else in order to do something useful with it.Â For this project, the end result will be a visualization of the GPS data in Flash Player on a Mac.Â There are myriad ways to accomplish this, however very few approaches can easily encapsulate all of these steps in a single language.Â This is because both low-level system access (to read the serial data) and some sort of server (to serve the data to Flash Player) are required.Â While it is definitely possible to use any number of other languages such as Java, Processing, C++, etc., performing all of these tasks with those languages would require significant amounts of code.
With that said, I opted for Python not only because I love it, but also because it is quite straightforward to use it to read from a serial port using the pyserial module and also to establish any number of different types of servers including standard HTTP and socket servers.Â While there are built-in libraries for creating and managing servers, I ultimately decided on creating a socket server using Twisted.Â Twisted is an enormously powerful networking framework that simplifies the creation of all sorts of servers.
Why add another framework when a standard HTTP server would suffice for serving up data to the Flash Player?Â The implementation of a standard HTTP server would require Flash Player polling the service to determine if data had been updated.Â So, rather than rely on that sub-par solution, Twisted makes the creation of socket servers very easy, which then allows the Flash Player to receive data in real-time via an XMLSocket connection.Â Not only that, but one of the coolest aspects of Twisted is that it makes it fairly easy to write multi-user socket servers, which will be a nice addition for future enhancements
Here is what the overall system architecture ends up looking like when all of that is considered:
However, before diving into these details, the first step is to hook up the device to the Mac via a serial Bluetooth connection and verifying that everything is working so far.
Bluetooth Pairing Obviously, the first step is to power up the board.Â After that, pairing the BlueSMiRF with the Mac.Â This is a very straightforward process.Â From the Bluetooth preference pane in System Preferences, click the "+" icon to add a new Bluetooth device.Â Advance through the dialog boxes, configuring the device that shows up as SparkFun-BT.Â The passkey for BlueSMiRF module is default, so type that in when prompted.
Once that's been done, by checking the serial interfaces in /dev, it can be verified that it is now active as a serial device.Â That is done by opening a terminal window and typing ls /dev/tty.*.Â That will list out all available serial interfaces.Â The BlueSMiRF should show up as something like tty.SparkFun-BT-COM0-1.
Screen Screen is a Unix application that allows one to attach a terminal session to a particular process.Â To view the serial communication that is happening on the serial port that the BlueSMiRF is attached to, this is a good option.Â This can be done by typing the following command into the terminal to view the serial communication on that port in realtime:
screen /dev/tty.SparkFun-BT-COM0-1 9600
Note that the 9600 at the end of that command is the baud rate.Â That command should yield some cryptic messages being printed in Terminal like the following if everything else is wired up properly:
To exit screen, hit control-a, then control-</em>.
The strings that are seen here are NMEA strings, which are derived from a specification that standardizes the way that marine electronics communicate with each other.Â For additional information on this, check out http://www.gpsinformation.org/dale/nmea.htm.Â If the GPS has a location fix, then numerous lines beginning with $GPGGA will be displayed, which precedes messages that contain the location fix data.Â Otherwise, there will be mostly $GPGSV, which represents data regarding the GPS satellites themselves.
OK, Now What?
Now that there is data coming in over a virtual serial port, the next step is writing the software.Â The next article in this series will examine the Twisted socket server and Flash XMLSocket connection along with providing the source code for those systems.