Adventures with a Nabaztag - wifi enabled rabbit!

 

Ever since I wrote in my book Analog In, Digital Out, how I hooked up a doorbell to my Mac so it rang when a visitor came to my site, I’ve always been fascinated with connecting real world objects to the internet. But the doorbell thing was a complete hack, involving java, a Making Things Teleo and a Flash embed on my site. It wasn’t exactly portable or easy to setup! Then along comes Nabaztag, and a whole host of possibilities suddenly open up.

The Nabaztag is a wifi enabled “rabbit” that has been around since about 2006, but somehow this little cute device has passed me by. Personally I’m not too sold on the design but I can live with it. It’s ears move, it lights up and most importantly, it speaks. It can also detect RFID for use with the zstamp.

I’m not going to do a product review of the Nabaztag. Instead I want to talk about, after two days of owning the rabbit, my experiences of setting it up and playing with the API to make it to do stuff.

Setting up

The first thing to say is the website for the Nabaztag is pretty awful. For instance on my.nabaztag.com they ask for your “nabname”. My what? Having already setup my Nabaztag on my.violet.net (yes there’s two sites - violet.net is for all the other violet products), there was no mention of a nabname. Turns out that the nabname is the email address (well just the bit before the @ sign) you give your Nabaztag! Totally confusing.

Anyway, the registration process was pretty easy. From either the my.violet.net site or the my.nabaztag.com site you can assign applications to your new rabbit buddy. I have to say though I couldn’t get any of the RSS feeds to work at all. The Twitter feed worked fine as did the clock.

Nabaztag and Apple Time Capsule

Quick mention here about setting up a Nabaztag with Apple’s Time Capsule. Having previously had it working fine at work, when I went to setup the rabbit on my home network I hit problems. I could connect to the wireless fine, but couldn’t connect to the internet. After an age Googling here and there, I found this website with the answer. Go to the advanced settings and change the address of the Violet Platform to 62.
210.186.165/vl (the last letter is a L). Once I did that it worked fine!

Exploring the API

What I really bought the Nabaztag for was to make my own stuff using the API. Like the website, the API is severely lacking, but with the help of some lovely people on Twitter I managed to get a little something together that takes the doorbell concept a lot further.

So what I built was a PHP script that sits on the homepage of my site. When anyone hits that homepage, the script sends a message to my Nabaztag, which randomly moves it’s ears, makes a noise and speaks the city and country of the visitor! I did also try to have it on every page of my site - but the messages were way too frequent. Here’s some video of the Nabaztag in action.


Of course this could go a lot further. Because you can alter the RGB of each of the four LEDs, it would be possible to light them up using the colours of that countries national flag. Would take a while to work out, but it’s definitely possible.

The source code is below, so take it, play around with it and be sure to let me know if you make something cool.


// Set serial number and token
$sn = 'SERIAL NUMBER';
$token = 'TOKEN';
$baseurl= 'http://api.nabaztag.com/vl/FR/api.jsp?sn='.$sn.'&token='.$token;

// get ip address
$ip=$_SERVER['REMOTE_ADDR'];

// get geo location
$contents = file_get_contents('http://api.hostip.info/get_html.php?ip='.$ip);

// strip out city and country
// probably a better way would be to use regular expressions but they make my brain hurt
$pieces = explode("Country: ", $contents);
$country = $pieces[1];
$location_of_character = strrpos($country,"(")-1;
$country = substr($country,0,$location_of_character);
$location_of_character = strrpos($pieces[1],":")+2;
$city = substr($pieces[1],$location_of_character,strlen($pieces[1]));
$location = urlencode($city.' '.$country);

// randomize ears
$leftear = rand(0, 15);
$rightear = rand(0,15);

if (empty($location)) {
    //echo 'fail';
} else {
	// construct message string
	$message = '&tts='.$location.'&ttlive=300&posleft='.$leftear.'&posright='.$rightear;
	$url = $baseurl.$message;
	// Set up and execute the curl process
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_exec($ch);
	// close cURL resource, and free up system resources
	curl_close($ch);
}

Comments

Leave a comment: