RSSImonitor.pl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/perl -w
  2. #
  3. # RSSImonitor.pl
  4. # (c) 2010 Dr. Boris Neubert
  5. # omega at online dot de
  6. #
  7. #
  8. # This perl script evaluates the RSSI information from
  9. # your devices in order to help you finding the best
  10. # location to place your CUL or CUN device.
  11. #
  12. # Instructions:
  13. #
  14. # 1. Make your CUN or CUL create additional events:
  15. # attr CUN addvaltrigger
  16. #
  17. # 2. Log the RSSI events to a single file:
  18. # define RSSI.log FileLog /path/to/RSSI.log .*:RSSI.*
  19. #
  20. # 3. Wait some time until all devices have sent something.
  21. #
  22. # 4. Run the log file through RSSImonitor:
  23. # RSSImonitor.pl < /path/to/RSSI.log
  24. #
  25. # 5. The output lists any device from the log together with
  26. # the minimum, maximum and average RSSI as well as its
  27. # standard deviation.
  28. #
  29. #
  30. # type perldoc perldsc to learn about hashes of arrays
  31. #
  32. use strict;
  33. my %RSSI;
  34. sub storeRSSI {
  35. my ($device, $value)= @_;
  36. if(!($RSSI{$device})) {
  37. $RSSI{$device}= [];
  38. #print "new device $device\n";
  39. }
  40. push @{ $RSSI{$device} }, $value;
  41. #print "device: $device, value: $value\n";
  42. }
  43. sub readRSSI {
  44. while( <> ) {
  45. my ($timestamp, $device, $keyword, $value)= split;
  46. if($keyword eq "RSSI:") {
  47. storeRSSI($device, $value);
  48. }
  49. }
  50. }
  51. sub calcStats {
  52. my ($device)= @_;
  53. my $min= 100.;
  54. my $max= -100.;
  55. my $m1= 0.;
  56. my $m2= 0.;
  57. my $n= $#{ $RSSI{$device} }+1;
  58. my ($i, $value);
  59. my ($avg, $sigma);
  60. foreach $i ( 0 .. $#{ $RSSI{$device} } ) {
  61. $value= $RSSI{$device}[$i];
  62. if($value< $min) { $min= $value; }
  63. if($value> $max) { $max= $value; }
  64. $m1+= $value;
  65. $m2+= $value*$value;
  66. }
  67. $avg= $m1/$n;
  68. $sigma= sqrt($m2/$n-$avg*$avg);
  69. return ($min, $max, $avg, $sigma);
  70. }
  71. #
  72. # main
  73. #
  74. readRSSI;
  75. my $device;
  76. printf("%12s\t%s\t%s\t%s\t%s\n", "Device", "Min", "Max", "Avg", "StdDev");
  77. foreach $device (keys %RSSI) {
  78. my ($min, $max, $avg, $sigma)= calcStats($device);
  79. printf("%12s\t%.1f\t%.1f\t%.1f\t%.1f\n", $device, $min, $max, $avg, $sigma);
  80. }