So if anyone is looking for a fun, geek-out project on a Sunday afternoon, this one will do nicely. You do not need to know how to write code to get this working.  You only need a computer (or virtual machine) with Ubuntu Linux with a working Bluetooth adapter, a Wii Balance Board, and the ability input the instructions below into a terminal.

1. Setting Up Your Computer to Talk with a Wii Balance Board:

Open up a command line terminal on your Linux machine. These instructions are for Ubuntu 9.x/10.x. Other Linux distributions instructions will vary. First install the prerequisites through your distribution’s package manager.

$ sudo apt-get install autoconf autogen automake gcc bluetooth libbluetooth3-dev libgtk2.0-dev pkg-config python2.6-dev flex bison git-core libbluetooth-dev python-pygame python-tk

Check out the CWiid (get it? CWiid? Seaweed?) library using Git:

$ mkdir bin
$ cd bin
$ git clone http://github.com/abstrakraft/cwiid.git
$ cd cwiid

Compile the Cwiid library. At the command line execute the following

$ aclocal
$ autoconf
$ ./configure
$ make
$ sudo make install

You can test things with a Wii Remote by running the GUI (This GUI will not work on a headless server)

$ wmgui

Lets now install the python bindings:

$ cd python
$ sudo python setup.py install

If this works, then your computer is now read to connect to the balance board. If you have problems please see the cwiid documentaion. These instructions were tested on Ubuntu 10.

2. Using the Wii Balance Board Application:

Run the weightdemo.py application and immedatly press the red button on the bottom of your balance board to sync the bluetooth connection. If all goes well you will see a GUI display on your computer.

If you haven’t already done so, download and install the python-omhe library.

$ git clone git://github.com/aviars/python-omhe.git

Change into the python-omhe directory:

$ cd python-omhe

Install the python-omhe library.

$ sudo python setup.py install

Change into the directory containing the Wii Balance server code.

$ cd omhe/hardware/wiibalance

Run th ewiibalance_weight.py application.  This applications sends an HTTP POST callback of the weight and a user ID each time you present a user ID from standard input.

$ python ./wiibalance_weight.py

If you get an error message, r/w error or a bluetooth connection timeout just run the application again. check to make sure you don’t have another python process running and trying to access the board. Press ‘q’ to exit the application. Anything else is interpreted as the user’s identifier. So this is designed to work well with a card reader, number pad, or any other standard input that helps identify the user. This is how we are binding the user to his or her weight. There is no format for user ID here. You can use whatever makes sense for you, but if you are using a RESTCat server in a standard configuration, then an email address might make the most sense.  Other tokens could include a user’s mobile phone number or  master patient index (MPI).

This applicating will do 3 things each time you press enter: * Send your weight (via callback) along with some other information * Write your weight to a JSON file (filename defined in settings.py) * Print the JSON file to standard output (Most often the screen).  This is the preferred method for serving your weight because it is more efficient, but just for an academic exercise, the following section will demonstrate how we can make the weight available via a web server.

3. Serve Your Weight through a Simple Web Server:

There are two ways to do this; a push and a pull. The tools found in python-omhe illustrate both methods.

3.1 Pushing Your Weight with an HTTP Callback:

wiibalance_weight.py will push your information with an HTTP callback at the address defined in your settings.py file. This means that we will perform an HTTP client POST containing the weight information. You must write and make avalaible your own callback handler at the URL specified in your settings.py.

3.2 Pulling (Polling) Weight from a Webserver:

There are many tools you could use to do what I’m doing here.  This includes Django, Pylons, PHP, you name it.  Using wiibalance_server.py you can make your weight avalaible via a webserver. wiibalance_server.py is a simple web server written in pure Python that simply serves the file containing the weight information. This file is generated by wiibalance_weight.py and its filepath is defined in settings.py. By default this file’s name is wiiweightout.json. So lets have an example shall we? Use this command to start the server:

$ python wiibalance_server.py

You should see the message:

Serve forever

Make sure you are using a port not used by another process (such as Apache, etc.) Change this in settings.py.

Now your serving your weight. Use your browser or open another terminal and use Curl to point to the URL. By default, the webserver is serving on port 8002 and will bind to any IP (0.0.0.0). The following command:

$ curl http://127.0.0.1:8002

Will yield a JSON file result counting the user’s ID and weight.  The weight is expressed in OMHE Microsyntax: http://code.google.com/p/omhe

I’ll point out that you can connect your output to a RESTCat server and hence have a very easy means for storage and retrieval via a RESTful API.

You can find RESTCat at: http://github.com/aviars/RESTCat

Have fun! If you find and errors or gotchas in this post please @reply me on Twitter.  My username is @aviars

-Alan

References:

Some of these instructions were modified from Matt Cutt’s blog article:
http://www.mattcutts.com/blog/linux-wii-balanceboard/