Coding a Networked Bike

October 14th, 2008 by josh

ybike screen

We’ve just finished a project for Yahoo called purple pedals (a.k.a. the yBike). There’s a good explanation of the project on Yahoo’s corporate blog and on lifehacker. In a nutshell, it’s a bike that takes pictures and uploads them to flickr in real time. Yahoo also produced some great videos about the project, and there have been a number of blog posts describing the project. But we decided it was time for us to post some details of our own for those interested in how it works.

This will be the first in a series of posts detailing how we chose the technology, the various challenges we faced, and why this project is interesting for us as a company. The Uncommon Projects team included myself (Josh Rooke-Ley), Tarikh Korula and Heather Dewey-Hagborg. We’re also indebted to early research from Michael Sharon and fabrication by Quill Hyde. This post will focus on my perspective as the software lead on the project.

Choosing the platform

One of the first technology questions on the project was whether we were going to use an off-the-shelf device, build the hardware ourselves, or employ some combination of both. From a software perspective, the decision can be described as a question of software versus firmware. Firmware is code that can’t be turned off — it is inextricably linked to the hardware it runs on. Moreover, firmware and hardware are generally designed together with one very specific function in mind and together are called an embedded system.

After several rounds of prototypes we ended up using an off-the-shelf GPS enabled cell-phone, the Nokia N95. I had some misgivings in choosing the N95. For one, the application we were designing was a machine-to-machine system. In other words, there wouldn’t be user interaction (except riding the bike) and there wouldn’t be a screen to give a rider feedback about the state of the application. It seemed very risky to use the N95 or any other off-the-shelf cellphone fundamentally designed to require user input and give screen-based feedback.

While the Nokia ended up being a great platform to work with, we did hit the wall a few times with issues that had no clear fix. For example, the code we wrote worked great, but one in every three times the application would quit unexpectedly after 6 hours of running continuously. And, while the python interface ended up being essential to rapid prototyping, it did mean loosing some control over low-level operations. We also experienced some issues with the python implementation of the camera library on the N95. Not to mention the arcane process of signing Symbian applications.

However, because there is support for background processing, task management, and run on-startup, we could work around any major software issue we encountered. These elements allowed us to make our software act more like firmware–in other words, we do everything possible to make sure that the software can’t quit unexpectedly and that it recovers in the worst possible case. It may not be elegant, but it works ™.

The picture at the top of the page shows the interface for the final application we wrote running on an N95. While this interface was not seen by the end-user it ended up being essential for development, debugging and administrator support.

The networking

The networking component of the project was straight forward compared to the device issues. Yahoo hired New York based web design firm Your Majesty to build startwearingpurple.com which includes flash-based map views of each of the bike photo streams. The geo-tagged images themselves are stored on flickr. For support and maintenance reasons we decided that the photo uploads would first be sent to a server application which would match the imei of the phone to a flickr account. This way we could change the flickr accounts remotely and monitor the status of all of the bikes with a web-based control panel. Here is a crude picture of the network architecture, clouds and all:

click to enlarge

And here is a screen shot of the admin control panel, which allows us to monitor activity, status (like battery level), and associate bikes with flickr accounts.

ybike-admin.png
click to enlarge

And finally, the source code

Yahoo was kind enough to let us share the source code for the project. Note that this code was designed to run in a controlled developer environment, not to be distributed to end-users. We are sharing it more as a reference for those out there that may be trying to do something similar. The code is shared under the GNU Lesser General Public Licence, so feel free to cut and paste into your own projects.

There are two components to the project: the client-side written in Python for S60 and the server-side which uses PHP, MySQL, and YUI. There is some limited documentation provided in README files provided with the source.

ybike_source.tar.gz

Postscript: some useful tidbits for nokia developers

For anyone out there attempting to do something like this project, here are a few useful bits of information that may come in handy.

  • If you want to understand the procedure for signing Symbian applications I recommend reading the guide from end-to-end. In fact, I had to read it several times before I understood it.
  • If you want to have your application run on startup there are two very important signing requirements:
    • You will have to use at least the “open-signed offline” procedure for signing (see the guide). The “open-signed online” procedure will not work. The upshot is you will have to obtain a publish id which costs $250 and requires faxing some documents to Europe. It may require you to be incorporated (not sure on this).
    • When you sign your application make sure you DON’T turn on the AllFiles, TCB, or DRM (i.e. device manufacturer) capabilities. It just won’t work.
  • The built in camera library that comes with Python for S60 v1.4.4 is broken, at least for N95’s. To fix the problem use the pycamera library which is distributed with Nokia’s open source computer vision library. Even with the pycamera library, you will have to force a delay of at least 2 seconds between initializing the camera and taking the picture to fix the over-exposure problem. See the take_photo function in the source code for an example.
  • Re-installing SIS files on the N95 sometimes caused the application to foreground on start up. This was a problem for us because it meant the keypad never locked. The only way to consistently prevent this seemed to be to do a hard reset on the phone then re-installing the sis files.
  • The European version of the N95 was required to get the application to work in Japan.

9 Responses to “Coding a Networked Bike”

  1. iam 62yr old and i think you guys are just great
    i have no knoledge of writing computer programes but this just blows my mind congrats& a big ” WOW”
    THIS IS JUST AMAZING TO ME.

    ME+++JOEKINDLY

  2. josh says:

    Well thank you, Mr. Mc Glue. It’s nice to know someone out there appreciates your work.

  3. Miguel says:

    I will follow suits to Mr. Mc Glue, and congrats you guys. This idea is just brilliant. Just when I thought I had “seen it all”. :)
    Ahh anyways, cheers from Toronto!

  4. Boz Hobbs says:

    Great work, but the above tech talk has an old man like me kinda scared to take the ball and run with it. I see security applications, and tourism and several others. Will you be selling a kit? Please! With some decent tech back up support.

  5. Verious says:

    It is very interesting to hear about the issues that arose during the development of this project and how your team was able to overcome them.

  6. phil suh says:

    I’ve got an idle N95 and am in Tokyo. Would like to give this a shot. Can you give some detail on why a European version of the N95 was required in Japan?

  7. josh says:

    I believe the issue is that the non-euro N95 doesn’t support the right network band — though I have read posts that say it should work. Note that we were using an AT&T account with an international plan, other providers may work. If your N95 can browse the internet, the code here should work for you. Let us know if you get it to work.

  8. I can’t believe I’m just finding out about this now…this is fantastic, you guys!

    You need to take these babies on tour. There’s an annual bike ride across the state of Iowa called RAGBRAI. Usually between 10-20K riders take to the roads of Iowa for a week in July. It would be awesome to see what you guys could photograph/track there…

  9. I found your blog on google and read a few of your other posts. I just added you to my Google News Reader. Keep up the good work. Look forward to reading more from you in the future.

Leave a Reply