Gauging Wireless AP Stability with a BeagleBone Black

| | 0 Comments| 12:32 PM
Categories:

It’s easy to roll your own wireless router with hostapd or OpenWRT and a BeagleBone Black and USB Wifi Adapter Dongle. In this post we’re going to roll our own Wifi AP stability tester. To follow along at home you’ll need a:

  • BeagleBone Black
  • Wifi USB Adapter
  • a tri-color LED

You will also need a microSD card and adapter so you can flash the final image on your BeagleBone. Note: We’ll use the term BeagleBone with a cavalier attitude, but we mean BeagleBone Black.

To build our Wifi AP tester, We went with a TP-LINK Nano adapter:

tplink
TP-LINK Wireless N Nano USB Adapter

And for the tri-color LED we picked up a Linrose Super Brite LED, Linrose part number B4361H1/5.

superbrite_led
Three Colors in One L.E.D.!

Preparing Your BeagleBone Black

We’re going to keep the OS simple and go with the latest console release of Debian 8.2 for the BeagleBone Black. The full release contains a desktop environment and we just don’t need that for something this simple.

Grab a release with something like:

and then write it out to your miniSD card where YOUR_DEVICE will be displayed in dmesg after inserting your SD card. Remember: dd is an acronym for disk destroyer so treat it with respect and make sure you have the right device.

Note: This page is the place to go to find the latest on Debian builds for BeagleBone Black.

Cable up your BeagleBone Black to your router via Ethernet. Pop the miniSD into your BeagleBone Black and press and hold the S2 button on the Black, and then apply power.

bbb_sdcard

Once the device boots ssh into it:

We’ve logged in as root here to speed things up. Feel free to use the debian user and insert sudo where necessary.

Software Prerequisites

Now we need to get our BeagleBone in shape to do a little hacking. Because we chose a barebones distribution image there are a few dependencies and “fix-ups” to do. Go ahead and run:

Now, why we installed all this stuff:

  • git because we’re going to git clone a repo containing the code for leveraging Speedtest.net to stress test our Wireless Access Point
  • build-essential because its a meta-package which contains essential packages for building applications, modules, libraries, etc.
  • python because we’re going to be using Python (speedtest-cli)
  • cpanminus for using the cpan tool down download, compile, and install Perl modules
  • wireless-tools firmware-realtek wpasupplicant to use our TP-LINK Wireless USB Adapter

If you’re using a Wireless adapter with a chipset other than RealTek, make sure and get the right firmware (apt-cache search wireless firmware helps).

It sounds like a lot, and in some ways it is, but consider the philosophy of building applications by “not reinventing the wheel.” Well, not reinventing the wheel doesn’t mean you don’t need wheels, and all of these packages are the wheels upon which we’ll take a trip.

One final note: the image we’re using doesn’t have locales installed, and so you get this annoying warning like this:

You can fix that by installing the locales package and configuring en_US.UTF-8.

Follow the onscreen prompts and select the en_US.UTF-8 locale.

We’re going to hack in Perl and Python today. Yes, you heard me, Perl! We use a few Perl libraries from CPAN (remember, not reinventing wheels here).

cpan will likely ask Would you like to configure as much as possible automatically? [yes]. Hit Enter to accept the default yes.

When prompted Is Net::Ifconfig::Wrapper info output correct? Y/N: verify that the eth0 entry looks good and answer (it should be).

Wifi

Use iwconfig to make sure your Wifi adapter is visible.

To get the wireless interface connected to your AP, edit /etc/network/interfaces and add your SSID and WPA (assuming you’re assuming WPA!) credentials. Make sure and uncomment the Wifi directives:

While you are in /etc/network/interfaces also change the eth0 entry from auto to allow-hotplug (more on this in a minute) like this:

Run ifup wlan0 to bring up your interface.

You should of course see a DHCPDISCOVER message go out followed by REQUEST, OFFER, and ACK.

The SSID you put in /etc/network/interfaces will be the SSID of the AP you intend to test.

Installing bbwifiaptest

Now let’s install our BeagleBone Wifi AP Tester. Grab it from GitHub.

The Perl script bbwifiaptest.pl is where the magic happens, and is what will be launched when we install the app as a service.

By default the script is designed to daemonize itself, but you can bypass this with --no-daemon on the command line. To start, try:

You should see something like:

You’re seeing the script use speedtest-cli to test the bandwidth of the connection and then display the statistics of the wlan0 interface. If we cannot reach Speedtest.net for whatever reason (presumably the AP is no longer routing us to the Internet) the script will retry 10 times and then give up.

Of course, our plan is to get a visual indication that the AP is available, so we’ll turn to our LED!

Lite-Brite!

Disclaimer: we’re not hardware heads over at iAchieved.it. If you feel there should be a current-limiting resistor for the LED, by all means, wire one up.

Now that we can run the bbwifiaptest script we need to plug in our tri-color LED. We’re using GPIO 66 and 67 which correspond to pins 7 and 8 on the P8 header of the BeagleBone Black. The cathode for the Linrose B4361H1/5 (the end that goes to ground) is the center pin and should be put in pin 1 or 2 of the P8 header, and the longer of the two anodes should be put in pin 7 of the P8 header. The shorter anode (red) should go in pin 8.

bbpins

Our color codes are as follows:

  • Green – speedtest.net is reachable and we’re downloading from it
  • Orange – speedtest.net is not available but we haven’t given up trying to contact it
  • Red – something is wrong and we’ve given up

An orange light can persist for up to a little over 6 minutes as the script patiently waits for the AP to come back online. After that it’s lights out.

Installing the Service and Testing

Now let’s install the application and set the BeagleBone to start it upon boot. Run the supplied install.sh script:

This script puts the speedtest-cli and bbwifiaptest.pl applications in /usr/local/bin and then enables a systemd daemon to start it once the network is available.

To test this you will need to:

  • have the LED plugged in
  • have the miniSD card plugged in

Log out of the BeagleBone, disconnect the Ethernet cable (we’re going to be running only on the Wifi dongle), and then press and hold the S2 button. While holding S2 down, press (but don’t hold) the Reset button (S1) on the BeagleBone. You can release S2 button after the blue LEDs start flashing. Be patient as the system boots – the LED will remain off until the Wifi connection is established and systemd starts the application. It will take about 30 seconds. One could get clever and create a prerequisite service that flashes the LED orange while the boot sequence is running.

FullSizeRender 17
Up and Running!

Remember when we changed eth0 from auto to allow-hotplug? This drastically reduces our boot time as systemd won’t sit around and wait for the Ethernet interface to come up (which it won’t). We do want it to wait for wlan0 which is why that is left to auto.

Look Ma, No Hands!

Remember up above where we had to press the S2 button to ensure the BeagleBone Black boots off of the microSD card? Well, if you ever pulled power in the tutorial above and forgot to press it again, you’re booting off of the onboard eMMC (which you can think of as a microSD card thats permanently soldered to the BeagleBone). When using our AP tester we don’t want to go around having to remember to press S2, so let’s flash our image to the eMMC. Warning: If you have something on the BeagleBone Black eMMC that you want to keep make sure and copy it off now! The next steps will erase whatever was there.

First, log in and go to /boot/uEnv.txt and go down to the bottom. You should see:

Heed the warning here about dosfstools and rsync and make sure they are installed (they should be). Then, uncomment the cmdline entry and reboot while holding down S2. Wait until all four of the LEDs next to the Ethernet connector light up, and then you can release S2. You should then see the LEDs light up in sequence back-and-forth, like this:

[youtube]https://www.youtube.com/watch?v=o885-0BmEpo[/youtube]

Once the flashing is complete the LEDs will go solid again. Disconnect power, pop out the microSD card, and then reapply power. Within 30 seconds or so you should see the green LED!

Now What?

Now you have a Wifi AP tester! Take your BeagleBone Black and locate it where ever you like in relation to your AP and power it on. If the device connects to the AP and begins downloading traffic you’ll see the green light. If it doesn’t light up at all you know something failed horribly and should reconnect the BeagleBone via Ethernet and take a look at the logs.

If you see the LED turn red after some time it means traffic was no longer getting out to the Internet. That is, for some reason, the AP stopped passing traffic. Again, turn off the device, cable it up, and take a look at the logs. You will be able to see when “traffic runs” started by the ENTRY and EXIT markers. You will want to write some post-processing script to generate reports about the data.

Command Line Options

The bbwifiaptest.pl script has a number of command-line options.

Option Description
--logfile LOGFILE Write logs to LOGFILE (default is /var/log/bbwifiaptest.log)
--speedtest SCRIPT Use SCRIPT for the speedtest-cli script.
--wirelessif WIRELESS_IF Use WIRELESS_IF as the wireless interface to monitor. Default is wlan0.
--no-daemon Don’t daemonize. By default the script will run as a daemon.
--log-console Display logs on the console. By default logs are only written to the logfile.

Next Steps

There’s so many things that can be improved here to make a sturdy little Wifi AP tester. Think multiline character displays with more status information, writing logs to the SD card, providing a web interface on port 80 to see what’s going on. You will also notice that the script isn’t designed to run while the Ethernet is plugged in – the green LED will come on because eth0 is passing traffic. We need to update the script to onlyuse Wifi.

We might make these changes and blog about them, but don’t wait on us, get hacking today! Finally, if you enjoyed this article make sure and follow @iachievedit on Twitter!

Leave a Reply

Your email address will not be published. Required fields are marked *