RubyCocoa: a simple wireless signal strength meter
Posted by Sandro Paganotti in
Ruby on Rails -
comments are closed
Yesterday, while reading the first chapter of an introduction to RubyCocoa I discovered how to play sounds with just few lines of ruby code.
Next I remembered a very useful post about How to get the wireless signal strenght from you airport and I decided to put togheter my (very small) knowledges of RubyCocoa to create a script that make your mac to work as an hot spot detector.
The next few lines of code use the wi-fi signal strength as a delay between two ‘beep’; this way the closer you get to the hotspot the less time pass between two ‘beep’ (it a sort of Geiger counter :)
Here is the code:
require 'osx/cocoa'
sound = OSX::NSSound.soundNamed 'Basso'
while true do
`airport -I` =~ /avgSignalLevel: -([0-9]+)/
delay = $1.to_i
puts "signal strenght: " + (delay/100.0).to_s
sound.play
sleep(delay/100.0)
end
I made it just for fun so I know that this script can be enhanced in a thousand ways (and it’s very far from perfection :).
Feel free to use this piece of code for everything you need and if you get a brilliant idea about how to improve it please let me know !
Sandro

