To connect my raspberry pi to a wifi network I am using a wifi USB device with a RTL8188CUS chipset. This is how I managed to connect that device to my raspberry pi which is equipped with a preloaded raspbmc image.
Normally the configuration of the wifi USB device should be very easy using the XBMC settings menu, but actually I didn’t want to make usage of the XBMC application at all. I just wanted to connect via ssh to the raspberry device without making usage of the graphical environment.
At first I had to deactivate NetworkManager as I want to configure the network settings manually from the commandline. Using NetworkManager concurrently to my manual configuration lead me to weird problems trying to bring up the wifi connection properly. Probably this is only necessary when using raspbmc. But not sure at all. At least it solved the mentioned problems I experienced.
You have to ensure to have the following packages installed on the raspberry to be able to configure the USB device as described below.
sudo apt-get install wireless-tools wpasupplicant usbutils
Install the necessary driver
To find out which chipset is implemented on the USB device I used lsusb which pointed to the mentioned chipset as mentioned earlier.
pi@raspbmc:~$ lsusb Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. Bus 001 Device 004: ID 0bda:8176 Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter
The last entry of that list indicates the USB device I had plugged to my raspberry. This information is relevant to find out the valid driver package to run properly the device. You will find the respective package with the needed firmware searching for the pattern ‚Realtek‘.
pi@raspbmc:~$ sudo apt-cache search Realtek firmware-realtek - Binary firmware for Realtek wired and wireless network adapters
Actually on my raspbmc this packages was already installed, which I figured out when I tried to install the package.
pi@raspbmc:~$ sudo apt-get install firmware-realtek Reading package lists... Done Building dependency tree Reading state information... Done firmware-realtek is already the newest version. 0 upgraded, 0 newly installed, 0 to remove and 10 not upgraded.
Setup the wifi connection
Now it should be possible to scan the wifi access points in range. The access point which should be connected to the raspberry should be listed as well. My access point is named CONNECTBOX. The other access points listed belong to my neighbors which are also in range.
pi@raspbmc:/$ iwlist wlan0 scan | grep ESSID ESSID:"NETSTAR1" ESSID:"NETSTAR2" ESSID:"AP1" ESSID:"LINK" ESSID:"CONNECTBOX"
The specific network, which should be connected to the raspberry device, has to be defined in the configuration file /etc/network/interfaces in the following manner. The loopback and eth0 adapter should be defined there as well.
pi@raspbmc:/$ sudo cat /etc/network/interfaces auto lo iface lo inet loopback iface eth0 inet dhcp iface default inet dhcp auto wlan0 iface wlan0 inet dhcp wpa-ssid "CONNECTBOX" wpa-psk "mypassword"
At this point an unencrypted password has been inserted for the respective adapter configuration. I would absolutely recommend to insert an encrypted password just for security reasons. An encrypted version of the password can be determined with the wpa_passphrase tool, passing the SSID name and the respective password as follows.
pi@raspbmc:/$ wpa_passphrase CONNECTBOX mypassword network={ ssid="CONNECTBOX" #psk="mypassword" psk=c41176098137e8678f03391079f29f9c5f43d4aab7da3526b7ab56b13ced6b413 }
You have to insert the value of the attribute psk to the /etc/network/interfaces configuration file, replacing the unencrypted value for wpa-psk.
pi@raspbmc:/$ sudo cat /etc/network/interfaces auto lo iface lo inet loopback iface eth0 inet dhcp iface default inet dhcp auto wlan0 iface wlan0 inet dhcp wpa-ssid "CONNECTBOX" wpa-psk c41176098137e80eff03391079f29f9c5f43d4aab7da39bb7ab56b13ced6b413
Please note the missing quote marks for the encrypted password!
The first start of the wifi connection can be started with the command ifup
pi@raspbmc:~$ sudo ifup wlan0 ioctl[SIOCSIWAP]: Operation not permitted ioctl[SIOCSIWENCODEEXT]: Invalid argument ioctl[SIOCSIWENCODEEXT]: Invalid argument Internet Systems Consortium DHCP Client 4.2.2 Copyright 2004-2011 Internet Systems Consortium. All rights reserved. For info, please visit https://www.isc.org/software/dhcp/ Listening on LPF/wlan0/00:11:c1:19:ad:5c Sending on LPF/wlan0/00:11:c1:19:ad:5c Sending on Socket/fallback DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 7 DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 8 DHCPREQUEST on wlan0 to 255.255.255.255 port 67 DHCPOFFER from 192.168.0.1 DHCPACK from 192.168.0.1 Reloading /etc/samba/smb.conf: smbd only. bound to 192.168.0.128 -- renewal in 516632 seconds.
From now on the wifi connection is being established with each start of the raspberry device.