Raspberry Pi: Getting started with Wi-Fi

Reviewed by Editor: Jack Allison

To have you RPi connected through Wireless LAN (Wi-Fi) you will need an appropriate USB-dongle.

I used EdiMax EW-7811Un (ebay). Although it has lower data-rate specification (150 Mb), there are some advantages: – small form-factor (size): good for small products/prototypes – fully supported (in plug-and-play fashion) by Raspbian – widely available at local stores in Israel for affordable price

Step-by-step (first usage)

To make your RPi connected to your home Wi-Fi Router do the following steps: – Plug the Wi-Fi dongle into RPi (powered-on or switched off) – If necessary, power-on your RPi – Use RPi’s WiFiConfig utility (on your desktop) to configure the WLAN settings: network name and password of your home Wi-Fi router. For that do the following 2 steps:

1) scan for available WLAN networks

2) chose your home network and enter the password

Auto-initialization (on power-up) of WiFi-interface.

Among the rest of connectivity benefits, Wi-Fi allows working on the RPi SW while the board is closed in a case. Instead being connected to RPi with a monitor trough HDMI cable, you can see RPi desktop remotely using VNC, TightVNC or Microsoft Remote Desktop utilities. In order to do this, you need the Wi-Fi dongle  initialized and to have valid IP address automatically assigned immediately after the RPi boot. The following steps describe how to achieve this goal: – Once you configured your RPi’s Wi-Fi interface to connect to your network (as described above), the connection details are saved and preserved at /etc/wpa_supplicant/wpa_supplicant.conf – To have the Wi-Fi initialization happen at the RPi’s boot add the following command to etc/rc.local :

sudo ifup wlan0

or

sudo ip link set wlan0 up

We are done with Wi-Fi and can start to enjoy our Wireless RPi  🙂

Static IP

It may be necessary to create a static IP address for RPi so that the router, via DHCP, does not assign different IP addresses which can cause problems when accessing RPi from the internet.  To create a static IP address for RPi, two files ned to be edited as follows:

1. /etc/network/interfaces

Add the rows as below replacing with your LAN addresses and netmask

The first parameter after iface command is interface name that you will use later so chose something meaningful

iface weather_station inet static
 address 192.168.0.120
 netmask 255.255.255.0
 gateway 192.168.0.1

2. /etc/wpa_supplicant/wpa_supplicant.conf

Add id_str variable that will link your wi-fi dongle to the static IP defined earlier

network={
 ssid="<name of your WLAN>"
 psk="<your WLAN password key>"
 proto=RSN
 key_mgmt=WPA-PSK
 pairwise=CCMP
 auth_alg=OPEN
   id_str="weather_station"
 }

Power Management

By default power saving feature may be On for Wi-Fi adapters. So that they go to sleep when aren’t used for a long time. As a result it takes a time (if possible at all) to awake this interface by ping command.

You may check if this feature is enabled by using a command:

iwconfig

If it is enabled and this is annoying and you would like immediate connectivity, you can disable this feature by adding of the  following line to the /etc/network/interfaces file

wireless-power off

After power reset use iwconfig command again to check if the new setting helped

Additional useful commands

sudo iwlist scanning
sudo allow-hotplug wlan0 eth0
sudo ifdown wlan0
sudo ifup --force wlan0 (note that DOUBLE-minus should appear before the 'force' parameter: at some web-browsers this example may show only one minus)

ipaddress reading

ifconfig

or

ip addr

Related References

Comments are closed.