Copyright Brian Starkey 2012-2014
Valid HTML 4.01 Transitional

Valid CSS!
iconUSB Network Monitormax, min, close
The GTK InterfaceThe GTK Interface
Introduction(top)
This is basically a USB controlled RGB LED. I had the hardware finished but had no real purpose for it, so I left it unused for almost a year. I had a GUI written, consisting of essentially just a GtkColorSelection, so I could set the LED colour to my heart's content, but that's as far as I got. Later in the year, I had some real issues with ISPs, and spent all of my time monitoring network downspeed with a gnome panel applet. All well and good, but then it hit me to use my LED as a network throughput monitor.

The BoardThe Board
Hardware & Firmware(top)
The circuit is very simple - it consists of an Attiny45, a common anode RGB LED (TruOpto Piranha), current limiting resistors, 2 diodes to drop VBUS to 3.6V and a USB socket. I'm not sure exactly what type of socket it is, it was salvaged from a cheap generic mp3 player, not that it really matters. There's a momentary push button on the board but currently it isn't wired to anything
The Attiny is running at 16.5 MHz off the internal oscillator. If anyone wants the schematic drop me a mail (contact details under Help - About)
The board is put inside the lid off a spray-snow can, makes a rather nice light diffuser, though is a little bit too opaque. The firmware uses V-USB, and is heavily based on the hid-custom-rq example by Christian Starkjohann (which seems to have disappeared - found a copy here)
It is also based on this project, which has a similar function: USB Mail Notifier
I implemented my own PWM loop, simply doing the appropriate LED switching. There is then a 'fade to' function, which takes a colour and a speed. It adjusts the R, G and B values to move the current colour to the required one, at the required speed.

The data-rate coloursThe data-rate colours
Output of the PC-side SoftwareOutput of the PC-side Software
Software(top)
The PC-side software is a bit of an ugly hack. It basically runs ifconfig every second, greps out the Tx and Rx byte figures, compares it to the last read values, and determines a data rate.
This rate is put through a few formulae:
if (kBps < 10) {
        if (inactive <= 85) inactive+=5;
        else if (inactive < 99) inactive++;
    }
    else {
        inactive = 0;
    }
    if (kBps < 60) {
        if (inactive) {
            data[0] = 100 - inactive;
            data[1] = 0;
            data[2] = 0;
        }
        else {
            data[0] = 150;
            data[1] = (unsigned char)(510*(1-cos(DEG2RAD(kBps))));
            data[2] = 0;
        }
    }
    else if (kBps < 120) {
        data[0] = 150-(unsigned char)(300*(1-cos(DEG2RAD(kBps-60))));
        data[1] = 255;
        data[2] = 0;
    }
    else if (kBps < 180) {
        data[0] = 0;
        data[1] = 255;
        data[2] = (unsigned char)(510*(1-cos(DEG2RAD(kBps-120))));
    }
    else if (kBps < 240) {
        data[0] = 0;
        data[1] = 255-(unsigned char)(510*(1-cos(DEG2RAD(kBps-180))));
        data[2] = 255;
    }
    else if (kBps < 300) {
        data[0] = (unsigned char)(300*(1-cos(DEG2RAD(kBps-240))));
        data[1] = 0;
        data[2] = 255;
    }
    else if (kBps < 360) {
        data[0] = 150;
        data[1] = (unsigned char)(510*(1-cos(DEG2RAD(kBps-300))));
        data[2] = 255;
    }
    else {
        data[0] = 255;
        data[1] = 255;
        data[2] = 255;
    }
Resulting in different colours for different data rates, as shown in the picture.
All the source code is avaialble in this zip.

iconVideo Playermax, min, close
Video(top)
The video shows the network monitor whilst loading webpages. The terminal window is the output of the PC-side software, the line graph in the bottom of the screen is gnome's network monitor.
There is around 1 second of lag between network traffic and the displayed colour. This is due to a) The refresh rate being 1 Hz, b) Averaging in software to stop the colours bouncing all over the place.
The light follows the gnome network monitor closely, which also has a 1 Hz refresh rate (and presumably software averaging.)

Images(top)