From 9b9930032228ea2e354b54598463eaad8685addb Mon Sep 17 00:00:00 2001 From: borisneubert Date: Mon, 27 Sep 2010 19:36:23 +0000 Subject: [PATCH] Added RSSImonitor.pl. git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@719 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- contrib/README | 4 ++ contrib/RSSImonitor.pl | 90 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100755 contrib/RSSImonitor.pl diff --git a/contrib/README b/contrib/README index 22d4f5436..578e5a514 100755 --- a/contrib/README +++ b/contrib/README @@ -61,3 +61,7 @@ - km271.pl Plain Buderus Logamatic 2107 communication module (KM271) logger See the 00_KM271.pm fhem module for its successor. +- RSSImonitor.pl + Produces an overview on the RSSI readings from a log. Good for checking + the signal quality at various locations for CUL and CUN. See begin of + script for usage instructions. diff --git a/contrib/RSSImonitor.pl b/contrib/RSSImonitor.pl new file mode 100755 index 000000000..29acfd6a4 --- /dev/null +++ b/contrib/RSSImonitor.pl @@ -0,0 +1,90 @@ +#!/usr/bin/perl -w + +# +# RSSImonitor.pl +# (c) 2010 Dr. Boris Neubert +# omega at online dot de +# +# +# This perl script evaluates the RSSI information from +# your devices in order to help you finding the best +# location to place your CUL or CUN device. +# +# Instructions: +# +# 1. Make your CUN or CUL create additional events: +# attr CUN addvaltrigger +# +# 2. Log the RSSI events to a single file: +# define RSSI.log FileLog /path/to/RSSI.log .*:RSSI.* +# +# 3. Wait some time until all devices have sent something. +# +# 4. Run the log file through RSSImonitor: +# RSSImonitor.pl < /path/to/RSSI.log +# +# 5. The output lists any device from the log together with +# the minimum, maximum and average RSSI as well as its +# standard deviation. +# +# +# type perldoc perldsc to learn about hashes of arrays +# + + +use strict; + +my %RSSI; + +sub storeRSSI { + my ($device, $value)= @_; + if(!($RSSI{$device})) { + $RSSI{$device}= []; + #print "new device $device\n"; + } + push @{ $RSSI{$device} }, $value; + #print "device: $device, value: $value\n"; +} + +sub readRSSI { + while( <> ) { + my ($timestamp, $device, $keyword, $value)= split; + if($keyword eq "RSSI:") { + storeRSSI($device, $value); + } + } +} + +sub calcStats { + my ($device)= @_; + my $min= 100.; + my $max= -100.; + my $m1= 0.; + my $m2= 0.; + my $n= $#{ $RSSI{$device} }+1; + my ($i, $value); + my ($avg, $sigma); + foreach $i ( 0 .. $#{ $RSSI{$device} } ) { + $value= $RSSI{$device}[$i]; + if($value< $min) { $min= $value; } + if($value> $max) { $max= $value; } + $m1+= $value; + $m2+= $value*$value; + } + $avg= $m1/$n; + $sigma= sqrt($m2/$n-$avg*$avg); + return ($min, $max, $avg, $sigma); +} + +# +# main +# + +readRSSI; + +my $device; +printf("%12s\t%s\t%s\t%s\t%s\n", "Device", "Min", "Max", "Avg", "StdDev"); +foreach $device (keys %RSSI) { + my ($min, $max, $avg, $sigma)= calcStats($device); + printf("%12s\t%.1f\t%.1f\t%.1f\t%.1f\n", $device, $min, $max, $avg, $sigma); +} \ No newline at end of file