Functionality in short: It captures WiFi packets from the air, and counts them. This then gets mapped to a scale from 0 to 10, and displayed on a rainbow-colored LED chart.
This runs on a Raspberry Pi Model B, although all the other models should work too.
I am using a $8 WiFi dongle
from Dealextreme. It just works™ after plugging into the RasPi.
lsusb reports it as
Ralink Technology, Corp. RT5370 Wireless Adapter with ID
Be sure to have an ethernet connection to your Raspberry Pi! During setup we will change the WiFi device to monitor mode and thus lose the wifi connection. So you could lock out yourself if you SSH into it using WiFi (although a restart will fix it).
sudo apt-get -y update sudo apt-get -y install iw python-scapy tcpdumppython-dev sudo pip install rpio # add a monitor device # test if monitoring works sudo iw phy phy0 interface add mon0 type monitor sudo iw dev wlan0 del sudo ifconfig mon0 up sudo iw dev mon0 set channel 6 # tcpdump should continuously list captured packages. Kill it with Ctrl-C. sudo tcpdump -i mon0 -n # teardown, back to normal wifi operation sudo iw dev mon0 del sudo iw phy phy0 interface add wlan0 type managed
Install our script
scp -r raspi-mon pi@<ip_of_your_pi>
On your Pi, add the following line to
/etc/rc.local (to enable autostart of the script):
sudo python /home/pi/raspi-mon/server.py &
Now, you have to wire up some LEDs from the Raspberry Pi GPIO pins. The RasPi has no problem outputting 10x 20mA, so you can connect them directly. Don't forget to add a resistor
to each LED although, except you want to destroy them in short time. I used ports
2, 3, 4, 17, 27, 22, 10, 9, 11, 7. If you use different ports, you should change this line
I used 2 LEDs per color, red, orange, green, blue, white.
- ScaPy for capturing packets
- iw for managing the WiFi device
- SQLite for data storage and simple analytics
I decided to use SQLite. It serves for multiple things simultaneously:
- Thread-safe communication between LED and capturing thread
- Easy data analytics (just SQL)
- Cheap storage on disk (well… SD-card)
There are some things running in parallel.
- One thread runs Scapy and sniffs. It logs all the beacon and data packets to the database.
- Another thread (
ChannelHopper) changes the wifi channel every 0.3 seconds. This is because we want to listen on all available channels, not just one..
- The third and last thread (main thread) pulls the data from the SQLite database and maps the captured activity to the LEDs. It then sleeps for one second, and repeats.
It works, although only on the 2.4GHZ band (the cheap adapter does not provide 5GHZ access). When I download something on my phone using a 2.4GHZ channel, I can see the LED bar going up! The whole thing is deployed in a cardboard box. It just runs after powering on (plugging in) the RasPi.Code on Github