Failed experiments and bad code for physical computing, data visualization and video delivery.

Bluetooth + GPS + Python + ActionScript - Part 2 - Hooking Up

Posted: November 6th, 2008 | Author: Barton | Filed under: AS3, Bluetooth, GPS, Physical Computing, Python, Twisted | Tags: | No Comments »

Overview

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.

Read the rest of this entry »