{"id":1760,"date":"2015-11-01T12:32:49","date_gmt":"2015-11-01T18:32:49","guid":{"rendered":"http:\/\/dev.iachieved.it\/iachievedit\/?p=1760"},"modified":"2020-05-13T18:09:06","modified_gmt":"2020-05-13T23:09:06","slug":"gauging-wireless-ap-stability-with-a-beaglebone-black","status":"publish","type":"post","link":"https:\/\/dev.iachieved.it\/iachievedit\/gauging-wireless-ap-stability-with-a-beaglebone-black\/","title":{"rendered":"Gauging Wireless AP Stability with a BeagleBone Black"},"content":{"rendered":"<p>It&#8217;s easy to roll your own wireless router with <a href=\"https:\/\/w1.fi\/hostapd\/\">hostapd<\/a> or <a href=\"https:\/\/openwrt.org\/\">OpenWRT<\/a> and a BeagleBone Black and <a href=\"http:\/\/www.diygadget.com\/802-11b-g-n-nano-usb-wifi-adapter-dongle-with-external-antenna-for-raspberry-pi-ralink-rt5370.html\">USB Wifi Adapter Dongle<\/a>. In this post we&#8217;re going to roll our own Wifi AP stability tester. To follow along at home you&#8217;ll need a:<\/p>\n<ul>\n<li>BeagleBone Black<\/li>\n<li>Wifi USB Adapter<\/li>\n<li>a tri-color LED<\/li>\n<\/ul>\n<p>You will also need a microSD card and adapter so you can flash the final image on your BeagleBone.  <b>Note:<\/b>  We&#8217;ll use the term BeagleBone with a cavalier attitude, but we <i>mean<\/i> BeagleBone Black.<\/p>\n<p>To build our Wifi AP tester, We went with a TP-LINK Nano adapter:<\/p>\n<figure id=\"attachment_1769\" aria-describedby=\"caption-attachment-1769\" style=\"width: 173px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/10\/tplink.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1769\" src=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/10\/tplink.jpg\" alt=\"tplink\" width=\"173\" height=\"239\" \/><\/a><figcaption id=\"caption-attachment-1769\" class=\"wp-caption-text\">TP-LINK Wireless N Nano USB Adapter<\/figcaption><\/figure>\n<p>And for the tri-color LED we picked up a <i>Linrose Super Brite LED<\/i>, Linrose part number B4361H1\/5.<\/p>\n<figure id=\"attachment_1767\" aria-describedby=\"caption-attachment-1767\" style=\"width: 181px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/10\/superbrite_led.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1767\" src=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/10\/superbrite_led.jpg\" alt=\"superbrite_led\" width=\"181\" height=\"480\" \/><\/a><figcaption id=\"caption-attachment-1767\" class=\"wp-caption-text\">Three Colors in One L.E.D.!<\/figcaption><\/figure>\n<h2>Preparing Your BeagleBone Black<\/h2>\n<p>We&#8217;re going to keep the OS simple and go with the latest <i>console<\/i> release of Debian 8.2 for the BeagleBone Black. The full release contains a desktop environment and we just don&#8217;t need that for something this simple.<\/p>\n<p>Grab a release with something like:<\/p>\n<pre>wget https:\/\/rcn-ee.com\/rootfs\/bb.org\/testing\/2015-10-25\/console\/bone-debian-8.2-console-armhf-2015-10-25-2gb.img.xz\n<\/pre>\n<p>and then write it out to your miniSD card where <code>YOUR_DEVICE<\/code> will be displayed in <code>dmesg<\/code> after inserting your SD card. Remember: <code>dd<\/code> is an acronym for <i>disk destroyer<\/i> so treat it with respect and make sure you have the right device.<\/p>\n<pre>$ xzcat bone-debian-8.2-console-armhf-2015-10-25-2gb.img.xz|sudo dd of=\/dev\/YOUR_DEVICE bs=8M\n0+137064 records in\n0+137064 records out\n1782579200 bytes (1.8 GB) copied, 144.855 s, 12.3 MB\/s\n<\/pre>\n<p><b>Note:<\/b> <a href=\"http:\/\/elinux.org\/Beagleboard:BeagleBoneBlack_Debian\">This page<\/a> is the place to go to find the latest on Debian builds for BeagleBone Black.<\/p>\n<p>Cable up your BeagleBone Black to your router via Ethernet. Pop the miniSD into your BeagleBone Black and press and hold the <b>S2<\/b> button on the Black, and <i>then<\/i> apply power.<\/p>\n<p><a href=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/10\/bbb_sdcard.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1762\" src=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/10\/bbb_sdcard.png\" alt=\"bbb_sdcard\" width=\"453\" height=\"431\" \/><\/a><\/p>\n<p>Once the device boots <code>ssh<\/code> into it:<\/p>\n<pre>Debian GNU\/Linux 8\n\nBeagleBoard.org Debian Image 2015-10-25\n\nSupport\/FAQ: http:\/\/elinux.org\/Beagleboard:BeagleBoneBlack_Debian\n\ndefault username:password is [debian:temppwd]\n\nroot@beaglebone:~#\n<\/pre>\n<p>We&#8217;ve logged in as <code>root<\/code> here to speed things up. Feel free to use the <code>debian<\/code> user and insert <code>sudo<\/code> where necessary.<\/p>\n<h3>Software Prerequisites<\/h3>\n<p>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 &#8220;fix-ups&#8221; to do. Go ahead and run:<\/p>\n<pre>apt-get update\napt-get install -y git build-essential python cpanminus wireless-tools firmware-realtek wpasupplicant\n<\/pre>\n<p>Now, why we installed all this stuff:<\/p>\n<ul>\n<li><code>git<\/code> because we&#8217;re going to <code>git clone<\/code> a repo containing the code for leveraging <a href=\"http:\/\/speedtest.net\">Speedtest.net<\/a> to stress test our Wireless Access Point<\/li>\n<li><code>build-essential<\/code> because its a meta-package which contains essential packages for building applications, modules, libraries, etc.<\/li>\n<li><code>python<\/code> because we&#8217;re going to be using Python (<code>speedtest-cli<\/code>)<\/li>\n<li><code>cpanminus<\/code> for using the <code>cpan<\/code> tool down download, compile, and install Perl modules<\/li>\n<li><code>wireless-tools firmware-realtek wpasupplicant<\/code> to use our TP-LINK Wireless USB Adapter<\/li>\n<\/ul>\n<p>If you&#8217;re using a Wireless adapter with a chipset other than RealTek, make sure and get the right firmware (<code>apt-cache search wireless firmware<\/code> helps).<\/p>\n<p>It sounds like a lot, and in some ways it is, but consider the philosophy of building applications by &#8220;not reinventing the wheel.&#8221; Well, not reinventing the wheel doesn&#8217;t mean you don&#8217;t <i>need<\/i> wheels, and all of these packages are the wheels upon which we&#8217;ll take a trip.<\/p>\n<p>One final note: the image we&#8217;re using doesn&#8217;t have locales installed, and so you get this annoying warning like this:<\/p>\n<pre>perl: warning: Setting locale failed.\nperl: warning: Please check that your locale settings:\n    LANGUAGE = (unset),\n    LC_ALL = (unset),\n    LC_CTYPE = \"en_US.UTF-8\",\n    LANG = \"en_US.UTF-8\"\n    are supported and installed on your system.\nperl: warning: Falling back to the standard locale (\"C\").\nlocale: Cannot set LC_CTYPE to default locale: No such file or directory\nlocale: Cannot set LC_MESSAGES to default locale: No such file or directory\nlocale: Cannot set LC_ALL to default locale: No such file or directory\n<\/pre>\n<p>You can fix that by installing the locales package and configuring en_US.UTF-8.<\/p>\n<pre>apt-get install -y locales && dpkg-reconfigure locales\n<\/pre>\n<p>Follow the onscreen prompts and select the en_US.UTF-8 locale.<\/p>\n<p>We&#8217;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).<\/p>\n<pre>cpan install Proc::ProcessTable Proc::Daemon Net::Int::Stats Net::Ifconfig::Wrapper\n<\/pre>\n<p><code>cpan<\/code> will likely ask <code>Would you like to configure as much as possible automatically? [yes]<\/code>.  Hit Enter to accept the default <code>yes<\/code>.<\/p>\n<p>When prompted <code>Is Net::Ifconfig::Wrapper info output correct? Y\/N:<\/code> verify that the <code>eth0<\/code> entry looks good and answer (it should be).<\/p>\n<h3>Wifi<\/h3>\n<p>Use <code>iwconfig<\/code> to make sure your Wifi adapter is visible.<\/p>\n<pre>root@beaglebone:~# iwconfig\nwlan0     unassociated  Nickname:\"<WIFI@REALTEK>\"\n          Mode:Auto  Frequency=2.412 GHz  Access Point: Not-Associated\n          Sensitivity:0\/0\n          Retry:off   RTS thr:off   Fragment thr:off\n          Encryption key:off\n          Power Management:off\n          Link Quality:0  Signal level:0  Noise level:0\n          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0\n          Tx excessive retries:0  Invalid misc:0   Missed beacon:0\n<\/pre>\n<p>To get the wireless interface connected to your AP, edit <code>\/etc\/network\/interfaces<\/code> and add your SSID and WPA (assuming you&#8217;re assuming WPA!) credentials. Make sure and <i>uncomment<\/i> the Wifi directives:<\/p>\n<pre># WiFi Example\nauto wlan0\niface wlan0 inet dhcp\n    wpa-ssid \"YOUR_SSID\"\n    wpa-psk  \"YOUR_PASSWORD\"\n<\/pre>\n<p>While you are in <code>\/etc\/network\/interfaces<\/code> <i>also<\/i> change the <code>eth0<\/code> entry from <code>auto<\/code> to <code>allow-hotplug<\/code> (more on this in a minute) like this:<\/p>\n<pre># The primary network interface\nallow-hotplug eth0\niface eth0 inet dhcp\n<\/pre>\n<p>Run <code>ifup wlan0<\/code> to bring up your interface.<\/p>\n<pre>root@beaglebone:~# ifup wlan0\n<\/pre>\n<p>You should of course see a <code>DHCPDISCOVER<\/code> message go out followed by <code>REQUEST<\/code>, <code>OFFER<\/code>, and <code>ACK<\/code>.<\/p>\n<p>The SSID you put in <code>\/etc\/network\/interfaces<\/code> will be the SSID of the AP you intend to test.<\/p>\n<h2>Installing bbwifiaptest<\/h2>\n<p>Now let&#8217;s install our BeagleBone Wifi AP Tester. Grab it from GitHub.<\/p>\n<pre>\ngit clone https:\/\/github.com\/iachievedit\/bbwifiaptest.git\n<\/pre>\n<p>The Perl script <code>bbwifiaptest.pl<\/code> is where the magic happens, and is what will be launched when we install the app as a service.<\/p>\n<p>By default the script is designed to <a>daemonize<\/a> itself, but you can bypass this with <code>--no-daemon<\/code> on the command line. To start, try:<\/p>\n<pre>.\/bbwifiaptest.pl --no-daemon --log-console\n<\/pre>\n<p>You should see something like:<\/p>\n<pre>Sun Nov  1 15:07:29 2015: [I] ENTRY\nSun Nov  1 15:07:29 2015: [I] START\nSun Nov  1 15:07:29 2015: [I] Using speedtest-cli at \/root\/bbonewifiaptester\/speedtest-cli\nSun Nov  1 15:07:29 2015: [I] wlan0 RX bytes:1977134453\nSun Nov  1 15:07:29 2015: [I] wlan0 TX bytes:9080413\nSun Nov  1 15:07:56 2015: [I] Download Speed: 45.62  Mbit\/s\nSun Nov  1 15:07:56 2015: [I] wlan0 RX bytes:2103578223\nSun Nov  1 15:07:56 2015: [I] wlan0 TX bytes:9084287\nSun Nov  1 15:08:18 2015: [I] Download Speed: 45.90  Mbit\/s\nSun Nov  1 15:08:18 2015: [I] wlan0 RX bytes:2204566330\nSun Nov  1 15:08:18 2015: [I] wlan0 TX bytes:9088091\n<\/pre>\n<p>You&#8217;re seeing the script use <code>speedtest-cli<\/code> 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.<\/p>\n<p>Of course, our plan is to get a visual indication that the AP is available, so we&#8217;ll turn to our LED!<\/p>\n<h3><a href=\"https:\/\/en.wikipedia.org\/wiki\/Lite-Brite\">Lite-Brite!<\/a><\/h3>\n<p><b>Disclaimer<\/b>: we&#8217;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.<\/p>\n<p>Now that we can run the <code>bbwifiaptest<\/code> script we need to plug in our tri-color LED. We&#8217;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 <i>center<\/i> pin and should be put in pin 1 or 2 of the P8 header, and the <i>longer<\/i> of the two anodes should be put in pin 7 of the P8 header. The shorter anode (red) should go in pin 8.<\/p>\n<p><a href=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/11\/bbpins.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1785\" src=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/11\/bbpins.jpg\" alt=\"bbpins\" width=\"600\" height=\"364\" \/><\/a><\/p>\n<p>Our color codes are as follows:<\/p>\n<ul>\n<li>Green  &#8211; speedtest.net is reachable and we&#8217;re downloading from it\n<li>Orange &#8211; speedtest.net is not available but we haven&#8217;t given up trying to contact it\n<li>Red    &#8211; something is wrong and we&#8217;ve given up\n<\/ul>\n<p>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&#8217;s lights out.<\/p>\n<h3>Installing the Service and Testing<\/h3>\n<p>Now let&#8217;s install the application and set the BeagleBone to start it upon boot. Run the supplied <code>install.sh<\/code> script:<\/p>\n<pre>root@beaglebone:~\/bbonewifiaptester# .\/install.sh\nCreated symlink from \/etc\/systemd\/system\/multi-user.target.wants\/bbwifiaptest.service to \/etc\/systemd\/system\/bbwifiaptest.service.\n<\/pre>\n<p>This script puts the <code>speedtest-cli<\/code> and <code>bbwifiaptest.pl<\/code> applications in <code>\/usr\/local\/bin<\/code> and then enables a <code>systemd<\/code> daemon to start it once the network is available.<\/p>\n<p>To test this you will need to:<\/p>\n<ul>\n<li>have the LED plugged in<\/li>\n<li>have the miniSD card plugged in<\/li>\n<\/ul>\n<p>Log out of the BeagleBone, disconnect the Ethernet cable (we&#8217;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&#8217;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 &#8211; 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.<\/p>\n<figure id=\"attachment_1795\" aria-describedby=\"caption-attachment-1795\" style=\"width: 297px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/11\/FullSizeRender-17.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1795\" src=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/11\/FullSizeRender-17.jpg\" alt=\"FullSizeRender 17\" width=\"297\" height=\"480\" \/><\/a><figcaption id=\"caption-attachment-1795\" class=\"wp-caption-text\">Up and Running!<\/figcaption><\/figure>\n<p>Remember when we changed <code>eth0<\/code> from <code>auto<\/code> to <code>allow-hotplug<\/code>?  This drastically reduces our boot time as <code>systemd<\/code> won&#8217;t sit around and wait for the Ethernet interface to come up (which it won&#8217;t).  We <i>do<\/i> want it to wait for <code>wlan0<\/code> which is why that is left to <code>auto<\/code>.<\/p>\n<h3>Look Ma, No Hands!<\/h3>\n<p>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&#8217;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&#8217;t want to go around having to remember to press S2, so let&#8217;s flash our image to the eMMC. <b>Warning<\/b>: 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.<\/p>\n<p>First, log in and go to <code>\/boot\/uEnv.txt<\/code> and go down to the bottom. You should see:<\/p>\n<pre>##enable Generic eMMC Flasher:\n##make sure, these tools are installed: dosfstools rsync\n#cmdline=init=\/opt\/scripts\/tools\/eMMC\/init-eMMC-flasher-v3.sh\n<\/pre>\n<p>Heed the warning here about <code>dosfstools<\/code> and <code>rsync<\/code> and make sure they are installed (they <i>should<\/i> be). Then, uncomment the <code>cmdline<\/code> entry and reboot while holding down S2. Wait until <i>all four<\/i> 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:<\/p>\n<p>[youtube]https:\/\/www.youtube.com\/watch?v=o885-0BmEpo[\/youtube]<\/p>\n<p>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!<\/p>\n<h2>Now What?<\/h2>\n<p>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&#8217;ll see the green light.  If it doesn&#8217;t light up at all you know something failed horribly and should reconnect the BeagleBone via Ethernet and take a look at the logs.<\/p>\n<p>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 &#8220;traffic runs&#8221; started by the <code>ENTRY<\/code> and <code>EXIT<\/code> markers.  You will want to write some post-processing script to generate reports about the data.<\/p>\n<h3>Command Line Options<\/h3>\n<p>The <code>bbwifiaptest.pl<\/code> script has a number of command-line options.<\/p>\n<table>\n<tr>\n<th>Option<\/th>\n<th>Description<\/th>\n<\/tr>\n<tr>\n<td><code>--logfile LOGFILE<\/code><\/td>\n<td>Write logs to LOGFILE (default is <code>\/var\/log\/bbwifiaptest.log<\/code>)<\/td>\n<\/tr>\n<tr>\n<td><code>--speedtest SCRIPT<\/code><\/td>\n<td>Use <code>SCRIPT<\/code> for the <code>speedtest-cli<\/code> script.<\/td>\n<\/tr>\n<tr>\n<td><code>--wirelessif WIRELESS_IF<\/code><\/td>\n<td>Use <code>WIRELESS_IF<\/code> as the wireless interface to monitor.  Default is <code>wlan0<\/code>.<\/td>\n<\/tr>\n<tr>\n<td><code>--no-daemon<\/code><\/td>\n<td>Don&#8217;t daemonize.  By default the script will run as a daemon.<\/td>\n<\/tr>\n<tr>\n<td><code>--log-console<\/code><\/td>\n<td>Display logs on the console.  By default logs are only written to the logfile.<\/td>\n<\/tr>\n<\/table>\n<h3>Next Steps<\/h3>\n<p>There&#8217;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&#8217;s going on.  You will also notice that the script isn&#8217;t designed to run while the Ethernet is plugged in &#8211; the green LED will come on because <code>eth0<\/code> is passing traffic.  We need to update the script to <i>only<\/i>use Wifi.<\/p>\n<p>We might make these changes and blog about them, but don&#8217;t wait on us, get hacking today!  Finally, if you enjoyed this article make sure and follow @iachievedit on Twitter!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;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&#8217;re going to roll our own Wifi AP stability tester. To follow along at home you&#8217;ll need a: BeagleBone Black Wifi USB Adapter a tri-color LED You will also need a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,22],"tags":[],"class_list":["post-1760","post","type-post","status-publish","format-standard","hentry","category-beaglebone","category-hacking"],"_links":{"self":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/1760"}],"collection":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/comments?post=1760"}],"version-history":[{"count":65,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/1760\/revisions"}],"predecessor-version":[{"id":3978,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/1760\/revisions\/3978"}],"wp:attachment":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/media?parent=1760"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/categories?post=1760"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/tags?post=1760"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}