Analog Mbit meter

I’ve picked up the idea of an analog megabit meter from Megabitmeter.de. Their talking about making a DIY kit, but the device is pretty simple. I decided not to wait and build one my own. This meter is basically an ‘Internet bandwidth meter’ which shows your bandwidth usage on a oldskool analog meter, like shown here:

Megabit Meter

The original on Megabitmeter.de lacks the basic schematic and a new meter face. I’ve just used a 10k potentiometer to adjust the meter. Furthermore I’ve created a new meter face in InkScape. This face can be downloaded here.

Your shopping list is:
Analog meter: Conrad PID: 120879-8Z
10k Potentiometer: Conrad PID: 432024-8A
Arduino Nano: Freeduino.eu

I’ve also made some improvements on the Perl script that megabitmeter.de uses. Their version calculates the bytes transferred within one second. This made my meter fluctuate alot so I’ve build my own PHP script that does the same thing, but instead uses the average of the last 5 calculations as meter value. This makes the meter less jumpy. The code is:


<?

function microtime_float()
{
 list($usec, $sec) = explode(" ", microtime());
 return preg_replace("/\./", "", $usec + $sec);
}

function getBytes()
{
 $handle = @fopen("/sys/class/net/eth0/statistics/rx_bytes", "r");
 if ($handle) {
 while (($buffer = fgets($handle, 4096)) !== false) {
 return preg_replace("/\n/", "", $buffer);
 }
 fclose($handle);
 }
}

function average($input) {
 return round(array_sum($input) / count($input), 0);
}


$oldValue = getBytes();
$gemiddelden = array(0, 0, 0, 0, 0, 0, 0, 0, 0);

$value = 1000000; // 1s
$value = 250000;

while (true) {
 $curValue = round(((getBytes() * 8) / $value), 0);

 $averageValue = average($gemiddelden);
 $newValue = round($curValue - $oldValue, 0);

 array_shift($gemiddelden);
 array_push($gemiddelden, $newValue);

 if (average($gemiddelden) > 100) {
 echo "100\n";
 } elseif (average($gemiddelden) < 0) {
 echo "0\n";
 } else {
 echo average($gemiddelden) . "\n";
 };

 $oldValue = $curValue;
 usleep($value);


};


?>

This entry was posted in Uncategorized. Bookmark the permalink.

One Response to Analog Mbit meter

  1. adaptive-vision.comHi!

    Nice work! I’ve stumbled across this article looking for images which I could use for my recognition algorithm. The algorithm reads a photo of analog meter and estimates the reading of the device ( it’s kind of funny to use it in this case, as the digital value is easy to obtain in the first place).

    Anyhow – it works like this: http://dxhp.webd.pl/kaiser/meter.jpg . Would You mind if I submit my algorithm ( along with Your picture ) to the samples repository of the software I use ( http://www.adaptive-vision.com/ ) for prototyping? The repository is shipped along with the software to each user. If You wish I could place a note about the author in the picture.

    Please let me know, that’s the most suitable picture I’ve found so far :).

Leave a Reply

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