diff --git a/files/usr/local/bin/snrlog b/files/usr/local/bin/snrlog index 0ff31e3a..7bf53f6d 100755 --- a/files/usr/local/bin/snrlog +++ b/files/usr/local/bin/snrlog @@ -35,8 +35,20 @@ $MAXLINES=2880; # 2 days worth $tmpdir="/tmp/snrlog"; +$lastdat="/tmp/snr.dat"; $sigdir="/sys/kernel/debug/ieee80211/phy0/netdev\:wlan0/stations"; +if ( -e $lastdat ) +{ + open(FILE, "<$lastdat") or die "Unable to read \"$lastdat\""; + while($line = ) + { + ($mac,$last) = split /\|/, $line; + chomp ($lasttime{$mac} = $last); + } + close FILE ; +} + $nf = `iw wlan0 survey dump | grep -A 1 'in use' | tail -1`; $nf =~ s/^[^-\d]*([-\d]+).*$/$1/; chomp $nf; @@ -45,20 +57,25 @@ if (! -e $tmpdir ) { system("mkdir $tmpdir > /dev/null"); } ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); $d = sprintf ("%02d/%02d %02d:%02d:%02d",$mon+1, $mday,$hour, $min, $sec); +chomp ($now=`cat /proc/uptime | cut -f1 -d" "`); foreach $sigmac ( `ls $sigdir` ) { chomp $sigmac; - $filename = `ls $tmpdir/$sigmac*` ; - $filename =~ /^.*\/([^-]*)-(.*)$/; - $isFile = $1; - $hnamef = $2; + $isFile = ""; + $hnamef = ""; + $ipsig = ""; + $macfname = ""; + $macfname = `ls $tmpdir/$sigmac*` ; + $macfname =~ /^.*\/([^-]*)-(.*)$/; + $isFile = $1; + $hnamef = $2; - chomp ($ip = `cat /proc/net/arp | grep $sigmac | cut -f1 -d\" "`); + chomp ($ipsig = `cat /proc/net/arp | grep $sigmac | cut -f1 -d\" "`); $hname=""; - foreach(`nslookup $ip`) + foreach(`nslookup $ipsig`) { - next unless ($hname) = /Address 1: $ip (\S+)/; + next unless ($hname) = /Address 1: $ipsig (\S+)/; $hname =~ s/\..*$// ; break; } @@ -67,9 +84,9 @@ foreach $sigmac ( `ls $sigdir` ) { $sigdat = "$sigmac-$hname"; } - elsif ( $hnamef eq $ip and $hname ) + elsif ( $hnamef eq $ipsig and $hname ) { - system("mv $tmpdir/$sigmac-$ip $tmpdir/$sigmac-$hname > /dev/null"); + system("mv $tmpdir/$sigmac-$ipsig $tmpdir/$sigmac-$hname > /dev/null"); $sigdat = "$sigmac-$hname"; } elsif ($hname and ! $hnamef and $isFile ) @@ -77,14 +94,14 @@ foreach $sigmac ( `ls $sigdir` ) system("mv $tmpdir/$sigmac- $tmpdir/$sigmac-$hname > /dev/null"); $sigdat = "$sigmac-$hname"; } - elsif (( $hnamef eq $ip) or ( $ip and ! $isFile )) + elsif (( $hnamef eq $ipsig) or ( $ipsig and ! $isFile )) { - $sigdat = "$sigmac-$ip"; + $sigdat = "$sigmac-$ipsig"; } - elsif ( $isFile and ! $hnamef and $ip ) + elsif ( $isFile and ! $hnamef and $ipsig ) { - system("mv $tmpdir/$sigmac- $tmpdir/$sigmac-$ip > /dev/null"); - $sigdat = "$sigmac-$ip"; + system("mv $tmpdir/$sigmac- $tmpdir/$sigmac-$ipsig > /dev/null"); + $sigdat = "$sigmac-$ipsig"; } elsif ($hnamef and ! $hname ) { @@ -101,7 +118,7 @@ foreach $sigmac ( `ls $sigdir` ) } chomp ($siglevel = `cat $sigdir/$sigmac/last_signal`) ; - if ($siglevel < -100 or $siglevel >= 0 ) { next; } + if ($siglevel < -95 or $siglevel >= 0 ) { $siglevel = "-95"; } open(my $fh, '>>', "$tmpdir/$sigdat") or die "Could not open file '$tmpdir/$sigdat' $!"; print $fh "$d,$siglevel,$nf\n"; @@ -114,4 +131,30 @@ foreach $sigmac ( `ls $sigdir` ) $rc=`tail -n$MAXLINES $tmpdir/$sigdat > $tmpdir/$sigdat.tmp`; $rc=`mv $tmpdir/$sigdat.tmp $tmpdir/$sigdat`; } + $neighbor{$sigmac}="1"; + $lasttime{$sigmac}=$now; } + +# process neigbors that are no longer connected +foreach $sigmac (`ls $tmpdir`) +{ + chomp $sigmac ; + $sigf = $sigmac; + $sigmac =~ s/-.*$//; + + if ( $now - $lasttime{$sigmac} > 25000 ) + { + unlink "$tmpdir/$sigf" ; + delete $lasttime{$sigmac}; + } + elsif ( ! $neighbor{$sigmac} ) + { + open(my $fh, '>>', "$tmpdir/$sigf") or die "Could not open file '$tmpdir/$sigf' $!"; + print $fh "$d,-95,-95\n"; + close $fh; + } +} + +open($fh, ">$lastdat") or die "Unable to create \"$lastdat\" $!"; +for (keys %lasttime) { print $fh "$_|$lasttime{$_}\n"; } +close $fh;