Thursday, July 21, 2011

CouchDB on Android

Lately, I've taken on a new project developing an application for Android mobile devices.

The company I'm doing this for gets assigned a building(s) to provide better cellular coverage for one or multiple carriers. There are extremely expensive devices that are specialized to take over-the-air (OTA) readings and map them out onto floor plans. The problem with that solution is not only the expense, but that the devices are perfectly tuned and calibrated unlike a standard handset. Enter Android.

Design Goals:

  1. Gather as much signal strength and location information from the handset as possible.
  2. Provide a way to load up a floor plan of a building and designate problem areas.
After discussing with my genius buddy Sean Summers. We decided it would be best to just keep gathering information from the phone when the app gets loaded and never stop. If a sufficient GPS reading is available, we would have data to discover the best available towers to get our donor signal from. With a little training on the app (ie: User must start application for 1 minute before entering building), this would give us the necessary information.

After creating the logging mechanism, I realized that we were recording over 1,000 records per minute! This isn't too big of a deal except that I need to get this data to my server and the user may or may not have internet coverage. We are going into a building with known coverage issues after all. Also, we are counting on each job having about 4-8 different models of Android phones (to detect anomalies among them) and each job could last up to 2 hours. So per job we were looking at upwards of 960,000 records.

Instead of focusing on how to create my own synchronization mechanism with checks and balances, I started looking into what Android had to offer. Enter CouchDB

I installed the CouchDB app from the market and manually configured it to sync to my home server. I also had to remove the timeout as the application will close itself after so long. I changed my data I was gathering into JSON and it worked beautifully.

Of course, I couldn't go through and manually install CouchDB on every device and configure them. That was when I ran into libcouch-android ( At first I got a little frustrated because I thought documentation was lacking and I was having some issues that I eventually worked out. Libcouch installs a very stripped down version of CouchDB and when started randomly generates and checks for a port to run on. I figured out it was sending me this port information in a call back that has since been documented. My other main issue was strictly PEBCAK. Too embarrassing to mention here :). On a related note, through my other genius friend Matt Turland, I discovered Rubberducking which I will religiously use from now on. Except I'm thinking of getting a Tux doll instead.

Nonetheless, my application is up and running and syncing data.


  1. couchdb app is not available on android market. so only way is to build it from android source?

  2. Which android smart phone would you recommend for a Sprint user like me? :)
    -Jackie (Virtual Receptionist)