Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Wireless Signal Tone Generator

by hardburn (Abbot)
on Feb 11, 2008 at 18:34 UTC ( #667424=CUFP: print w/ replies, xml ) Need Help??

Get's the signal from iwconfig and plays a tone based on the strength. Higher tone = better signal.

Useful for:

  • Taking a laptop around the house finding deadspots
  • Aiming a directional antenna

And probably a bunch of other stuff.

This won't work on operating systems that don't use wireless-tools. Sorry. Also won't work if your wireless driver doesn't report the signal strength. Sorry.

You may want to tweak some of the constants at the top. At the very least, make sure $INTERFACE points to the right device.

#!/usr/bin/perl # # Wireless Signal Tone Generator # Copyright (C) 2008 Timm Murray # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License al +ong # with this program; if not, write to the Free Software Foundation, In +c., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # use strict; use warnings; use Audio::Data; use Audio::Play; use Time::HiRes 'usleep'; my $DEBUG = 0; $ENV{PATH} = '/bin:/usr/bin'; # Highest and lowest frequencies played my $LOW_FREQ = 400; my $HIGH_FREQ = 2600; # Highest and lowest signal power (usually expressed in negative dB) my $LOW_SIGNAL = -100; my $HIGH_SIGNAL = 0; # Amplitude of the sine wave generated my $AMP = 0.1; # Timing factors for the program sleeping and the sine wave length, re +spectively my $SLEEP_DELAY = 500_000; # microseconds my $AUDIO_DELAY = 0.5; # seconds (can be decimal number) # The granularity of the scale my $SCALE = 100; # Interface name to check my $INTERFACE = 'wlan0'; # Path to iwconfig program my $IWCONFIG = '/sbin/iwconfig'; my $audio_play = Audio::Play->new; $SIG{INT} = sub { $audio_play->flush; exit 0; }; my @freq_scale = scale( $HIGH_FREQ, $LOW_FREQ, $SCALE ); my @signal_scale = scale( $HIGH_SIGNAL, $LOW_SIGNAL, $SCALE ); my %scale = map { $signal_scale[$_] => $freq_scale[$_] } 0 .. $#signal +_scale; sub set_rate { my ($audio_data, $audio_play) = @_; $audio_data->rate( 8000 ); if( $audio_data->rate != $audio_play->rate ) { $audio_play->rate( $audio_data->rate ); if( $audio_data->rate != $audio_play->rate ) { warn "Converting to " . $audio_play->rate . " Hz\n"; $audio_data->rate( $audio_play->rate ); } } return 1; } sub scale { my ($high, $low, $scale) = @_; my $range = $high - $low; my $percent = $range / $scale; my @scale = map $low + $percent * $_, 0 .. $scale; return @scale; } sub get_signal { my $got = `$IWCONFIG $INTERFACE`; my ($signal) = $got =~ / Signal \s+ level [:=] \s* ([\d\-]+) /x; $signal = $HIGH_SIGNAL if $signal > $HIGH_SIGNAL; $signal = $LOW_SIGNAL if $signal < $LOW_SIGNAL; return $signal; } sub debug { my ($in) = @_; print $in . "\n" if $DEBUG; return 1; } { my @signal = map -1 * $_, 0 .. 100; my $i = 0; sub get_test_signal { $i = 0 if $i > $#signal; return $signal[$i++]; } } { while( 1 ) { #my $signal = get_test_signal; my $signal = get_signal; my $freq = $scale{$signal}; debug( "Signal ${signal}dB, freq ${freq}" ); my $audio_data = Audio::Data->new; set_rate( $audio_data, $audio_play ); $audio_data->tone( $freq, $AUDIO_DELAY, $AMP ); $audio_play->play( $audio_data ); usleep $SLEEP_DELAY; } }

"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Comment on Wireless Signal Tone Generator
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://667424]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2014-11-23 07:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (129 votes), past polls