Updated on 2019 with simplified settings!
Setting WiFi on Raspberry Pi is easier than described earlier. The Raspberry Pi has gone through upgrades and generations, so most of the settings have been simplified. If you set up WiFi using GUI, then it same as on any windows – you select SSID and enter a password.
Raspberry pi should be mostly accessed through the console since it is designed to be an embedded computer. This is why it is important to have the ability to do all things in the command line.
No matter which raspberry pi you have, you can set wireless networks the same way. If you use Raspberry Pi 1 or 2, you will need a USB wireless adapter. The later boards already come with built-in WiFi and Bluetooth connectivity.
To set up WiFi, you need to edit wpa-supplicant configuration file, which can be accessed by entering:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
To the bottom of file add your network settings as follows:
network={
ssid="Network_SSID"
psk="wifi_password"
}
Save settings by pressing CTRL+X and Y to confirm. You may need to reboot your board for the network to connect.
Raspberry Pi Model B comes with an Ethernet interface built-in where you can plug cable and have internet access. In many cases, this is enough, but what if you want it to be more portable and still be able to connect to it? One solution would be using a Wi-Fi adapter. Since there are a couple of USB connectors, probably the best choice would be using USB-based Wi-Fi modules. You can get them in a very compact size that isn’t that good at sensitivity and range or choose bigger ones with an antenna. No matter what type you select – all of them work the pretty same way.
For my experiment, I am going to use a cheap Wireless adapter EDUP model EP-N8508. It supports all the necessary features and standards that are needed to have WiFi. The small form factor makes it attractive to use on many devices like laptops and Raspberry Pi. You may need to use a powered USB hub to get reliable performance. For now, I am using it attached to one of the USB ports directly.
As always, to learn and understand, we are going to set up Wi-Fi from the command line using PuTTY. So for this, we will need an Ethernet connection.
First of all, log in to Raspberry Pi and run the command:
sudo nano /etc/network/interfaces
Here you should see
auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
With the latest Raspbian, all: loopback, Ethernet, and WLAN interfaces should be present. If not, then add missing parts. Be sure that wlan0 is using DHCP (not manual) IP configuration.
To configure the Wi-Fi connection to a secured network open configuration file by running the command:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
and edit it to connect to a WPA secured network:
pi@raspberrypi ~ $ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="your ssid"
scan_ssid=1
proto=WPA
key_mgmt=WPA-PSK
pairwise=TKIP
auth_alg=OPEN
psk="yourkey"
id_str="edup"
}
Until Wi-Fi adapter isn’t plugged in you can run the command:
ifconfig
to see that there are two interfaces active – loopback and eth0:
pi@raspberrypi ~ $ ifconfig
eth0 Link encap:Ethernet HWaddr b8:27:eb:72:2d:bd
inet addr:192.168.1.214 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:517500 errors:0 dropped:0 overruns:0 frame:0
TX packets:280158 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:24861065 (23.7 MiB) TX bytes:14249246 (13.5 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1104 (1.0 KiB) TX bytes:1104 (1.0 KiB)
No Ethernet yet. Now plug in the adapter and reboot Raspberry Pi either completely with
sudo shutdown -r 1
or
sudo reboot
Also, you can disconnect and reconnect wlan0 adapter only so you don’t: have to reboot. For this first run:
sudo ifdown wlan0
and then:
sudo ifup wlan0
then you will see the message:
ioctl[SIOCSIWAP]: Operation not permitted
ioctl[SIOCSIWENCODEEXT]: Invalid argument
ioctl[SIOCSIWENCODEEXT]: Invalid argument
which can be ignored.
After wlan0 is connected you can run the ifconfig command again to check if wlan0 has its IP address assigned. Also, you can scan access points with the command;
sudo iwlist wlan0 scan
Now when you see your Wi-Fi is working, you can remove the ethernet cable and reboot. This will make wifi become the default network interface.
I am sure you will run into several problems like mistyping things, setting something wrong. Actually, it took a couple of hours to get this working. With Linux, you should get used to this – in the command line, you can’t miss anything as there is no GUI that does this for you. If you have a different adapter, you may need to check this list to find common problems.