For some time now I have been looking for a light that can be easily controlled from a desktop computer or server. The original intention was to have a red lamp in the office hallway and light it up when the unit tests break.
One solution to that idea is using a network-controllable power outlet strip and plug a normal lamp in there. Problem here is the price tag, which is above 100€.
Another solution would be to solder a lamp with an USB connector myself; there are numerous tutorials about that on the internet. Since I am inherently lazy, this was only my last resort when there was no other way out.
Some days ago I came across the DreamCheeky Webmail notifier which actually is a USB lamp with differently colored LEDs inside that can be controlled via USB. After discovering that there is also a linux driver for it, I bought it at the local thinkgeek instance for 15€.
Yesterday it arrived by mail, 5 minutes later the controller program was installed - which supports passing in hex color codes, i.e. usblamp '#FF8000' for a nice orange - and an hour later I had a cron script running that sets the color of the mail notifier according to the load of one of our development servers. The serverload-munin code is part of daniel's git repository now.
The script expects that munin-node (version 1.x) is installed and running on the server, since fetching the load value is really easy using netcat on munin-node's plain text protocol on port 4949.
Update 2010-12-22: Linux kernel drivers on the way
I just got a mail forwarded by Melchior Franz, noting that Greg Kroah-Hartman accepted Melchior's patch into his usb-next kernel tree ! This means that in the next merge window the patch will get into the linux mainline kernel. Wow! That was really fast.
The kernel already had a USBLED driver for Delcom's USB Visual Signal Indicator, exposing virtual files for red, green and blue in the /sys/ file system. Now that driver has been extended to support Dream Cheeky's DL100B Webmail Notifier - which also brings us support for connecting multiple usb lamps to the computer! This one was lacking in the usblamp tool on github and I already considered implementing it. You've gotta love Open Source for such moments.
Update 2010-12-23: Pimped USB Lamp
Melchior sent a link to photos of his pimped lamp - he removed the original cover and replaced it with one from a bicycle lamp.
Oh, and Conrad sells the lamp for 10€ now.
Update 2011-10-15: Kernel driver usage
Ubuntu 11.10 (Oneiric) ships Linux 3.0.0 which has the drivers included. Multiple lamps are supported!
When attached, the log shows the following:
$ dmesg|tail -n3 [72465.130847] usb 2-1.2: USB disconnect, device number 6 [72468.909763] usb 2-1.2: new low speed USB device number 7 using ehci_hcd [72469.025013] usbled 2-1.2:1.0: USB LED device now attached
Finding the lamp devices
$ find /sys -name green /sys/devices/pci0000:00/0000:00:1a.7/usb1/1-1/1-1.3/1-1.3:1.0/green /sys/devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1.2/2-1.2:1.0/green
2 lamps are attached here.
Changing the color
You may use values from 0 to 255 in the files red, green and blue.
$ cd /sys/devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1.2/2-1.2:1.0/ $ echo 255 > red $ echo 255 > green $ echo 255 > blue
For me, red 50 is the same as red 255.
When the lamp gets plugged in, it is only usable for the root user. To fix this, an udev rule is needed.
Put the following line into /etc/udev/rules.d/99-usblamp.rules. It will run a shell script whenever an usb lamp is plugged in:
SUBSYSTEM=="usb", DRIVER=="usbled", RUN+="/etc/udev/symlink-usblamp.sh"
Now create the shell script /etc/udev/symlink-usblamp.sh and make it executable:
#!/bin/sh path=/sys$DEVPATH chmod g+w $path/red $path/green $path/blue chgrp lampe $path/red $path/green $path/blue
When booting the computer with the lamp attached, the rule does not get called. You may work around this problem by putting a
udevadm trigger --action=change
into your /etc/rc.local file.
If you know how to fix this properly without messing with rc.local, please tell me.
Other people with the same idea
Laurence Sheed uses the eBuddy for server load and door entry monitoring .