Tue Dec 1 03:39:44 EST 2009

the search for a smart clock

assembled ybox2

This is a ybox2. It makes a pretty lousy alarm clock.

Of course, being a weird kinda guy, I have some weird requirements for an alarm clock.

The first problem is that my uncorrected eyesight is so terrible that I can't read 5 centimeter tall numerals from a distance of thirty centimeters. Once you move out of the nightstand form factor, things start getting Expensive. So I bought a couple of awesomely beefy LED numerals, which sat on my bench, unused, since I didn't have a power supply that could supply enough volts to light them.

Sparkfun makes a wall clock controller, which is great, except that at the time it was expensive, was designed to run DIY 7-segment numerals, and used GPS as a time source, which is inconvenient for an indoor clock.

Today, however, it's a hundred dollars cheaper, would work great with regular LED 7-segment numerals, but now runs on an internal time source, which still isn't ideal because I refuse spend money on yet another clock that I have to manually set, and correct for daylight savings time. I hate daylight savings time, the pointless garbage that it is, and if I have to manually adjust yet another clock for it I'm going to have to start murdering.

As for setting the time, well, I'm just lazy.

Now, clocks for people too lazy to set them is a mature market, well served by clocks that can receive NIST time signals or more expensive ones that can receive GPS time. But the problem here is that both of these are government services. Using these for time-keeping assumes that: the government will fund these for perpetuity, the government will always believe that it is in its best interests for its citizens to have accurate time, and that the government will exist.

Rather than depend on that dubious series of assertions, I would rather provide my own time standard, with the option of using another. Unfortunately for my wallet, these requirements are so narrow and oddly shaped that only NTP fulfills them. NTP is pretty damn lightweight, but it still requires a full PC to run.

Embedded-formfactor computers with real linux support are esoteric, and therefore expensive. But I've got full-size computers all over the place, which only my sense of aesthetics preventing me from using one to run a clock.

There is also the ybox2. It's based around an eight core (!) microprocessor, uses any television with a composite video input as a display, and the default widget is a clock, which suggestively "gets its time from a Navy timeserver". But can a microprocessor run a full implementation of the NTP client?

That's an excellent question, one I answered by purchasing it.

The ybox2, like the ybox before it, is designed around the Parallax Propeller, an 8 cored, 80mhz microprocessor, like a mini-Cell processor. That's the good news. The bad news is that it has a phat 32 kilobytes of ram, making it more of a crippled Cell processor. Parallax makes great hay about the Propeller being a 32-bit processor, which is curious, since 32-bit architectures are mostly used for their ability to easily access larger amounts of ram.

In addition, the ybox2 is designed to fit in an Altoids tin. That's cool, I'm down with the curiously strong mint, except the Propeller and the ethernet driver are both DIP chips, and are thus long and skinny. In order to get everything to fit, the cables attach at either end of the device, a profoundly awkward form factor for a set top box.

The pseudo-NTP alarm clock widget, alarmclock.spin, the reason I bought the ybox2, manages to fit a networking stack, a HTTP client, a HTTP server, the actual clock code, and a twinkly little LED throbber all in 32 kilobytes of ram, a miracle of efficient coding. It also features the most egregiously ugly hack I've ever seen in a piece of commercial software.

You see, alarmclock.spin doesn't use NTP to set its clock. That's disappointing, since that's its reason for existence, but NTP isn't really meant for embedded hardware like the ybox2. Unfortunately, it doesn't implement Simple NTP either, which is meant for embedded hardware like the ybox2. It doesn't implement TIME or DAYTIME, either.

Well just how does it set its clock, then?

Good thing you asked, italics man! You see, first it sends a HTTP 1.0 request to tycho.usno.navy.mil. Not HTTP 1.1, since the ybox2 doesn't implement all of TCP. Well, actually, it sends that request to 199.211.133.239, which is hard-coded in alarmclock.spin, since it doesn't support DNS either.

The file it requests from 199.211.133.239 is /cgi-bin/timer.pl, which alarmclock.spin then screenscrapes for the UTC time, which it applies the time zone offset to.

Wow.

Wow indeed, italics man. Let's list the ways this could break.

  1. Tycho could change its IP address.
  2. Tycho could stop accepting HTTP 1.0 connections.
  3. Tycho could stop accepting connections from clients with ybox2's user agent
  4. Tycho could move timer.pl, or delete it entirely.
  5. Timer.pl could display its timestamp in such a way that alarmclock.spin couldn't extract it anymore.
  6. Someone could execute alarmclock.spin's author for crimes against software engineering, resulting in,
  7. The ybox being eradicated from the timestream through retroactive causation.

So, the ybox ain't a NTP clock, and never will be one, without porting NTP to it entirely, which sounds like Work.

The search continues!