Wednesday, November 24, 2010

Chumby Webserver Without the Flash Drive

This summer, I bought a Chumby as my birthday present for myself.  For those who don't know, the Chumby is an internet-connected alarm clock, meaning my desk-side clock can do such fun things as scroll by my most recent email, play Pandora, and display the weather forecast.  I opted for the Chumby One, saving me a little money compared to the Classic and it better matches my style, I feel.
Click here to visit my Chumby!

Most importantly, the Chumby runs Linux.  Much like the games I've been playing with my WRT54G[L] routers, this means I can make the Chumby do so much more than it's originally presented to do.

The one that particularly interested me, for no good reason, was getting a web server setup on the Chumby.  To think that I was server a website from my alarm clock is just the kind of ridiculous idea I revel in.

The (outstanding) Chumby wiki already has excellent documentation as to how to setup lighttpd as the web server on the Chumby, but has the one short-fall of all being contained on a flash drive which has to stay plugged into the back of the Chumby for the web server to work.  What I really wanted was for all of the storage to be internal to the Chumby, so that I can still pick it up and interact with it like I normally do.

Fortunately, the microSD card inside the Chumby used to store the firmware has additional storage capacity, which is formatted and mounted as /mnt/storage/.  Unfortunately, I timed buying my Chumby when they were building them with 1GB SD cards, which leaves about 500MB for /mnt/storage/, to be shared between this web server, and all of my mp3s that I store on it to play when my internet / wifi isn't cooperating enough to listen to Pandora.  This isn't nearly enough for my taste, but I happen to have had an 8GB microSD card laying around with no use, and found instructions to upgrade the SD card inside the Chumby, which I did.

Now that I have 7GB of FLASH storage to play with, it has become only a software issue, which is easy, right?

Not so much.  The directory prefix of the /lighty/lib folder is a compile-time option, which means the binary posted on the wiki didn't work for me (There may be a config option for it, but I didn't find it).  This left compiling the entire lighttpd package from source, which turned out to not be that bad, once you get the dev environment setup, which I've become pretty good at in Linux (AVR, MSP430, WRT54G[L]).

I simply compiled the lighttpd server from source using the configure option:
--prefix=/mnt/storage/lighty
instead of the
--prefix=/mnt/usb/lighty
option documented in the wiki.  Once the compile was complete, I scp'd the finished binary to the Chumby to finish the install.

This suffers from the one shortfall of how to start it.  The USB-based web server used the debugchumby script in the root of the flash drive, but with no flash drive, I have no debugchumby script there to use.  Again, the Chumby wiki has an entire page devoted to documenting the different injection points for scripts to be run.  Moving the sample debugchumby script to /psp/rfs1/userhook1 got my web server to start when I rebooted the Chumby.

Prebuilt tarball of lighty to be extracted in /mnt/storage/
If you're not big into the whole wasting an hour of your life trying to get an ARM compiler working, here is my working binaries and scripts.  The easiest way to get the tarball onto the Chumby would be to load it onto a flash drive, then SSH into the Chumby and move it around from there.

At this point, I have an entirely working web server, which also logs every request to the microSD card for later analysis, if I'm interested.  As it stands, I have little more intest than just how many requests a day are handled, so to prevent the log files from growing out of control, I wrote a small log rotation script to be run by cron at the end of every day, which counts the number of lines in the lighty.access.log file, appends that and the current date to another log file, and moves the access log file to lighty.access.log.yesterday, to give me some sort of chance of reviewing what requests are being made (a lot of bots looking for wiki and wordpress admin pages).  This script can be stored anywhere, and only needs to be added to the cron table by manually adding the following to /psp/crontab/root:
59 23 * * * /mnt/storage/lighty/logrotate.sh

Note that the crontab shipping with the Chumby doesn't default to the correct folder, so to edit the cron table requires crontab -c /psp/crontabs/ -e.

logrotate.sh


I am working on adding on to this script to have it cause a growl notification on my desktop with the day's statistics, as well as email me the raw logs, but I'm working remotely from my parent's house for the weekend, so I can't test that until next week.  Feel free to do what you like with it, and let me know in the comments.

You can visit my bedside web site here: kwf.dyndns.org:5821

21 comments:

  1. Cool! That's a heck of a fast processor in that thing... sparks the imagination, doesn't it?

    ReplyDelete
  2. Some hot clock! how much power does it take?

    ReplyDelete
  3. Cool. Does it still perform its alarm functions under recent load? (What with it being featured on hn and all that..)

    ReplyDelete
  4. @Anon: I don't recall off-hand what the power specs are on the Chumby One, but the fact that it can run for an hour off a Li-ion battery bodes well for it being reasonably low.

    @Anon: My internet connection is the limiting factor for the web hosting, so lighttpd never goes above 0.7%. Load average is sitting at 1.5, which doesn't make any sense, and I'm 100 miles away from it, so I can't make any judgements as to how responsive it is.

    ReplyDelete
  5. Hi,

    to make your Chumby immediately accessible from everywhere without touching your firewall/NAT and nothing more than a Web server Alias you could use YalerTunnel from http://yaler.org/

    Cheers,
    Thomas

    ReplyDelete
  6. wow! it's cool... I reckon it's more than a toy but not a clock LOL

    ReplyDelete
  7. Astonishing :) Just saw the news in Hacker News and checking website to see how it is going to handle the digg effect.

    If I were your, I would use a second alarm clock tonight ;) It is going to crash soon under too much geek attention.

    ReplyDelete
  8. 哇噻,太厉害了。本来我也想要去买一个玩的,可是她的价格实在是太贵了,2000RMB再加上关税实在是让我难以接受。

    ReplyDelete
  9. @凡尘飞扬: I can appreciate that. Even without tariff it hurt at $120USD, but considering how much I've been using it both for its built-in features like Pandora.com, and the extra hacking projects like this one, I feel it has justified itself, to me at least.

    ReplyDelete
  10. Ken, that's amazing. But interference on the same band that wireless networking uses? Odd. It might be caused by your neighbor's units, or a leaky, which means older microwave. CF: The frequency band used by both Wireless networking all sorts, and the odd Microwave oven, and unfortunately some newer cordless phones happens to the unlicensed and unmanaged band so the Feds aren't interested.

    ReplyDelete
  11. @Gregg: Living in a complex of 100+ apartments means I am completely surrounded by cheap wifi routers, built-in microwaves, baby-monitors, etc etc. My router can see two dozen APs. Between the apartments and the PG&E substation across the street, not only is 2.4GHz poor, the noise floor is terrible wall to wall.

    Down in HF the floor is S9+20 all the way up to 6m, and only drops to S3-5 by 2m. It being an apartment means I'm only going to live here another year, and don't have the space for any serious radio anyways, so I'm just tolerating it for now. Amateur radio has just been shelved for a while.

    ReplyDelete
  12. Do you still have the tarball of lighty that you can upload somewhere or send to me? The MF link above is dead.

    ReplyDelete
    Replies
    1. Good to know. Thanks. http://kwf.dyndns.org:5821/files/lighty.tar.gz

      Delete
    2. That link doesn't seem to connect. Can you please check?

      Delete
    3. I'm currently moving, so my Chumby is sitting in a box.

      Delete
    4. Will this be back up anytime soon?

      Delete
    5. Alright... I managed to get it plugged into a random outlet in my parent's house and shuffled all my dyndns records. It's possibly up now, but no warranty expressed or implied on their even-less-impressive home DSL connection.

      Really, learning how to setup a cross-compile build chain is a growth experience... :-P

      Delete
    6. I meant to download this the other day when I was able to ping your device but the port was blocked where I was located. Now that I'm home, it appears that your Chumby is down again. Will this be up soon for me to grab a copy?

      Delete
    7. I managed to crash my router remotely this afternoon. It should be back up tomorrow or Thursday when I get home to physically power cycle my router.

      Delete
    8. Also, try it without any port redirection. This is now my primary web host on my network.

      Delete