From a6e3549284e744c2020fbfaa60d592fccb49fca9 Mon Sep 17 00:00:00 2001 From: borisneubert <> Date: Wed, 3 Oct 2012 18:23:42 +0000 Subject: [PATCH] added 99_RpiUtils.pm from jowiemann a t debitel d o t n e t git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@1918 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- contrib/99_RpiUtils.pm | 124 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 contrib/99_RpiUtils.pm diff --git a/contrib/99_RpiUtils.pm b/contrib/99_RpiUtils.pm new file mode 100644 index 000000000..7b2458edc --- /dev/null +++ b/contrib/99_RpiUtils.pm @@ -0,0 +1,124 @@ +############################################## +# $Id: 99_RpiUtils.pm $ +package main; + +use strict; +use warnings; +use POSIX; + +sub +RpiUtils_Initialize($$) +{ + my ($hash) = @_; +} + +sub +ShowRpiValues () +{ + +my @uptime = explode(" ", qx(cat /proc/uptime)); +my $seconds = @uptime[0]; +my $y = floor($seconds / 60/60/24/365); +my $d = floor($seconds/60/60/24) % 365; +my $h = floor(($seconds / 3600) % 24); +my $m = floor(($seconds / 60) % 60); +my $s = $seconds % 60; + +my $string = ''; + +if($y > 0) +{ + my $yw = $y > 1 ? ' Jahre ' : ' Jahr '; + $string .= $y . $yw . '
'; +} + +if($d > 0) +{ + my $dw = $d > 1 ? ' Tage ' : ' Tag '; + $string .= $d . $dw . '
'; +} + +if($h > 0) +{ + my $hw = $h > 1 ? ' Stunden ' : ' Stunde '; + $string .= $h . $hw. '
'; +} + +if($m > 0) +{ + my $mw = $m > 1 ? ' Minuten ' : ' Minute '; + $string .= $m . $mw . '
'; +} + +if($s > 0) +{ + my $sw = $s > 1 ? ' Sekunden ' : ' Sekunde '; + $string .= $s . $sw . '
'; +} + +# my $uptime = "Uptime:\n" . preg_replace('/\s+/',' ',$string); + +my $dataThroughput = qx(ifconfig eth0 | grep RX\\ bytes); +$dataThroughput =~ s/RX bytes://; +$dataThroughput =~ s/TX bytes://; +$dataThroughput = trim($dataThroughput); + +my @dataThroughput = split(/ /, $dataThroughput); + +my $rxRaw = $dataThroughput[0] / 1024 / 1024; +my $txRaw = $dataThroughput[4] / 1024 / 1024; +my $rx = sprintf ("%.2f", $rxRaw, 2)." "; +my $tx = sprintf ("%.2f", $txRaw, 2); +my $totalRxTx = $rx + $tx; + +my $network = "Received: " . $rx . " MB" . "
" . "Sent: " . $tx . " MB" . "
" . "Total: " . $totalRxTx . " MB"; + +my @speicher = qx(free -mo); +shift @speicher; +my ($fs_desc, $total, $used, $free, $shared, $buffers, $cached) = split(/\s+/, @speicher[0]); + +shift @speicher; +my ($fs_desc, $total2, $used2, $free2, $shared2, $buffers2, $cached2) = split(/\s+/, @speicher[0]); + +my $percentage = sprintf ("%.2f", (($used - $buffers - $cached) / $total * 100), 0); +my $ram = "RAM: " . $percentage . "%" . "
" . "Free: " . ($free + $buffers + $cached) . " MB" . "
" . "Used: " . ($total - $buffers - $cached) . " MB" . "
" . "Total: " . $total . " MB"; +$percentage = sprintf ("%.2f", ($used2 / $total2 * 100), 0); +my $swap = "Swap: " . $percentage . "%" . "
" . "Free: " . $free2 . " MB" . "
" . "Used: " . $used2 . " MB" . "
" . "Total: " . $total2 . " MB"; + + +my $Temperatur=sprintf ("%.2f", qx(cat /sys/class/thermal/thermal_zone0/temp) / 1000); + +my @filesystems = qx(df /dev/root); +shift @filesystems; +my ($fs_desc, $all, $used, $avail, $fused) = split(/\s+/, @filesystems[0]); +my $out = "Groesse: ".sprintf ("%.2f", (($all)/1024))." MB
"."Benutzt: ".sprintf ("%.2f", (($used)/1024))." MB
"."Verfuegbar: ".sprintf ("%.2f", (($avail)/1024))." MB"; +#sprintf("%0.2f%%",$df_free); + +my %RpiValues = +( + "1. RpiCPUTemperature" => $Temperatur.' Grad', + "2. RpiCPUSpeed" => substr(qx(cat /proc/cpuinfo | grep BogoMIPS),11).' MHz', + "3. RpiUpTime" => $string, + "4. RpiRAM" => $ram, + "5. RpiSwap" => $swap, + "6. RpiSD-Card" => $out, + "7. RpiEthernet" => $network, +); + +my $tag; +my $value; +my $div_class=""; + +my $htmlcode = '
\n"; + +foreach $tag (sort keys %RpiValues) +{ + $htmlcode .= "\n"; +} + +$htmlcode .= "\n"; +$htmlcode .= "
$tag : $RpiValues{$tag}
"; +return $htmlcode; +} + +1;