Thursday, January 3, 2013

Beaglebone: Using an USB WiFi dongle to connect to wireless networks at boot.

I'll cover how I configured my BeagleBone so it now (automagically) connects to wireless networks at boot.

Note: I assume you are running Ubuntu 12.10 in your Beaglebone.

Manual connection


First, let's check whether the Beaglebone can use the WiFi dongle by setting up a manual connection.

Before starting the test, let's install some software with the ethernet cable plugged in:
#On the beaglebone
sudo apt-get install lshw
sudo apt-get install wpasupplicant
Now unplug the Ethernet cable from the Beaglebone. And start a connection using the USB emulated Serial connection.
# On the PC
screen /dev/<ttyUSBx> 115200
Now let's check if the Beaglebone has recognized the WiFi dongle.
# On the beaglebone
lshw -C network
I got this:
*-network:1 DISABLED
description: Wireless interface
physical id: 2
bus info: usb@1:1
logical name: wlan0
serial: d8:eb:97:12:e4:c0
capabilities: ethernet physical wireless
configuration: broadcast=yes driver=rtl8192cu driverversion=3.2.33-psp26 firmware=N/A multicast=yes wireless=IEEE 802.11bgn
If you see something similar, it means your device has been detected by the Linux kernel and an appropriate driver has been loaded.

Remember the logical name, in this case is wlan0.

Now, turn on the WiFi dongle. (Use the logical name obtained from the last command)
# On the beaglebone
sudo ifconfig wlan0 up

Blue LED indicates that the WiFi dongle has been turned ON.

Scan for visible WiFi networks.
# On the beaglebone
sudo iwlist wlan0 scanning
You should see your network in the list:
wlan0     Scan completed :
          Cell 01 - Address: 00:13:49:CA:F5:10
                    Channel:4
                    Frequency:2.427 GHz (Channel 4)
                    Quality=56/70  Signal level=-54 dBm
                    Encryption key:on
                    ESSID:"your-ssid"
                    ...
Now, let's connect to your network.
# On the beaglebone
sudo nano /etc/network/interfaces
Append or modify the file to include the following text (I'm assuming your network it's WEP protected):
auto wlan0
iface wlan0 inet dhcp
    wireless-essid <ssid>
    wireless-key s:<ascii key>
Next, start the connection
# On the beaglebone
sudo ifup wlan0
And finally, test the connection
# On the beaglebone
ping www.google.com

Congratulations, you have connected to a wireless network.

Going automatic


We'll use wpa_supplicant to automate the connections to wireless networks.

wpa_supplicant is a daemon that manages unsecure, WEP and WPA wireless connections.

wpa_supplicant stores the information about the wireless networks that it can connect to in a .conf file, usually named wpa_supplicant.conf.

You can create/edit it, using:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
This is how it should look like:
ctrl_interface=/var/run/wpa_supplicant

# Unsecure Network
network={
    ssid="<ssid>"
    key_mgmt=NONE
    priority=<unsecure_priority>
}

# WEP Network
network={
    ssid="<ssid>"
    key_mgmt=NONE
    wep_key0="<key>"
    priority=<wep_priority>
}

# WPA Network
network={
    ssid="<ssid>"
    psk="<passphrase>"
    priority=<wpa_priority>
}

For more examples about the .conf file, check this website.

Let's reconfigure the network interface to add support for wpa_supplicant.
sudo nano /etc/network/interfaces
Change the wlan0 part to match the following text:
auto wlan0
iface wlan0 inet dhcp
    wpa-driver wext
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Finally reboot the BeagleBone to see the changes.
sudo reboot
Done!

10 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. Excellent tutorial, thanks! I used a Edimax EW-7811Un with no problems at all.

    ReplyDelete
  3. Which wireless dongle have you used?

    ReplyDelete
    Replies
    1. Hello Hyon,

      For this tutorial I used a Trendnet dongle, the model is TEW-648UBM, a.k.a. N150 Micro Wireless USB Adapter.

      It's based on the rtl8192cu chipset.

      Delete
  4. can this tutorial be followed for beagle board xm rev C as well?

    ReplyDelete
  5. and one more thing is that 12.10 version is important to setup wireless connection?? cuz i have ubuntu 11.10 running on my beagle board,12.10 was quite slow so i had to change it

    ReplyDelete
  6. hi can i use a wifi data stick on an Ångström image? and can u help me setup my bone on a lan network?

    ReplyDelete
  7. how can i do the same if i hav an angstrom image on my beagle bone black.. Guess al the commands above wont wrk! please let me know

    ReplyDelete
  8. forget the rtl8192cu chipset with Angstrom, it will not work reliably. Using Ubuntu is the right choice

    ReplyDelete
  9. Thanks for this tutorial - information is spot-on and it helped me a lot.

    ReplyDelete