Karotz: Movies Application

The Karotz (née Nabaztag) is an Internet-connected embedded system in the form of a stylized mechanical rabbit. I received one of these as a gift, and it’s actually kind of cool. It lacks any kind of display (other than a single multi-color LED), but does have such amenities as a camera, microphone, RFID reader, motorized ears, robust text-to-speech and a Javascript API.

My first application for the Karotz is called Movies. It scrapes the Google movie listings, and reads you upcoming titles and showtimes for the theater of your choice. Full source download and additional discussion after the break.

First, a brief disclaimer: While I’ve been programming for a while, this is not only my first Karotz app, it’s my first Javascript app. I’m not claiming everything (or anything) in there is best-practices, robust, portable  or even right (though it does seem to work, at least coincidentally, when I use it).

I’m posting here in the hope that it’ll be useful to others who are writing their own Karotz apps, but also in the hope that I’ll get constructive criticism. So, if you see something dumb, call me on it. I don’t promise to always agree, but you won’t hurt my feelings. Telling me it sucks is encouraged so long as you detail the specific nature of the suckage in question.

So, the sources:

(Both of the above are identical save for the means of archiving.)

Some specific lessons learned:

  • Go through the tutorial and get a “hello world” program working first (on the virtual machine, then on the physical device).
  • When you’re testing with the VM, settings won’t be available in the same way they are when you’re running “for real”. See the initialization block near the top of the connected() function in my source for one way to deal with this.
  • The values you get from params[instanceName].whatever are strings. When you’re faking parameters for the VM, your fakes should be strings too, not scalars. If you mess this up, you’ll get an app that tests fine but fails when deployed to the device, and it’ll be very hard to debug.
  • If you are trying to debug something that only happens on the real device, logging to an external webserver can be extremely valuable. See hlog() in my source.
  • In Javascript, 1+2=3 but 1+’2’=’12’. If you are used to the way other (strongly typed) languages do it, the type-promotion (and the way it combines with operator overloading) can lead to surprises.

[Updated 2012 Nov 08 by DGH to fix broken download links]

By dhenke

Email: dhenke@mythopoeic.org

Leave a comment

Your email address will not be published. Required fields are marked *