Raspberry Pi Wireless Networking

If you are trying to figure out how to manually configure the wireless network on your Raspberry Pi then you should be able to find what you need here.

I’ve included examples showing how to identify the wireless network device and install the correct firmware on the Raspberry Pi 1, 2, 3+ and Pi Zero W. These examples are based on the latest version of Raspbian (Stretch), however the instructions should still work with earlier versions though the firmware packages may have different names.

Note – I’m starting with a minimal install, if you are using one of the Raspbian images all of the packages you need should already be installed.  

As always you need to start by being logged in as a root.

 
Welcome to Raspbian GNU/Linux 9 (stretch)!
 
[  OK  ] Created slice User and Session Slice.
[  OK  ] Created slice System Slice.
  :
  :
  :
[  OK  ] Started Update UTMP about System Runlevel Changes.
[  OK  ] Started Load/Save RF Kill Switch Status.
 
Raspbian GNU/Linux 9 Pi ttyAMA0
Pi login: root
Password: 
Last login: Sun Jan 13 01:11:26 UTC 2019 on ttyAMA0
Linux Pi 4.14.79+ #1159 Sun Nov 4 17:28:08 GMT 2018 armv6l
 
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
 
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

Or

su
Password: 

Installing the firmware

We need to begin by adding the contrib and non-free repositories to the list of repositories that will be used when installing new packages.

nano /etc/apt/sources.list

/etc/apt/sources.list
deb http://mirrordirector.raspbian.org/raspbian stretch main contrib non-free firmware

Then we need to re-synchronize the package index files.

apt-get update
Hit:1 http://mirrordirector.raspbian.org/raspbian stretch InRelease
Hit:2 http://archive.raspberrypi.org/debian stretch InRelease
Reading package lists... Done

As the Raspberry Pi uses a USB wireless adaptor you will also need to install the USB utilities to allow you to see what USB devices are present.

apt-get install usbutils --no-install-recommends
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libusb-1.0-0
Suggested packages:
  wget | lynx-cur
The following NEW packages will be installed:
  libusb-1.0-0 usbutils
0 upgraded, 2 newly installed, 0 to remove and 2 not upgraded.
Need to get 257 kB of archives.
After this operation, 828 kB of additional disk space will be used.
Do you want to continue? [Y/n] 
  :
  :
  :
Setting up usbutils (1:007-4) ...
 

Now we can look at the USB devices properties and use them to work out what firmware packages we need to install (which can be easier said then done!)…

I’ve described how to install the correct firmware for some common adapters below. Once you have managed to install the correct firmware then you can continue to configure your wireless network using the instructions further down the page.

Raspberry Pi 1 or 2 with a RT5370 Nano Adapter

Fortunately it is easy to identify this particular adapter from the device description (highlighted in red below).

lsusb
Bus 001 Device 004: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Searching the available packages for suitable candidates based on the manufacturer reveals there are two possible candidates.

apt-cache search ralink
firmware-misc-nonfree - Binary firmware for various drivers in the Linux kernel
firmware-ralink - Binary firmware for Ralink wireless cards (dummmy package)

In this case you actually need ‘firmware-misc-nonfree’, but if you try to install ‘firmware-ralink’ instead you will get a message saying that it depends on ‘firmware-misc-nonfree’.

apt-get install firmware-misc-nonfree --no-install-recommends
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  initramfs-tools
The following NEW packages will be installed:
  firmware-misc-nonfree
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 0 B/2321 kB of archives.
After this operation, 8155 kB of additional disk space will be used.
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package firmware-misc-nonfree.
(Reading database ... 11960 files and directories currently installed.)
Preparing to unpack .../firmware-misc-nonfree_1%3a20161130-3+rpt4_all.deb ...
Unpacking firmware-misc-nonfree (1:20161130-3+rpt4) ...
Setting up firmware-misc-nonfree (1:20161130-3+rpt4) ...
 

Raspberry Pi 1 or 2 with the Official Wireless Adapter

lsusb
Bus 001 Device 004: ID 0a5c:bd1e Broadcom Corp
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

apt-cache search broadcom |grep firmware
firmware-b43-installer - firmware installer for the b43 driver
firmware-b43legacy-installer - firmware installer for the b43legacy driver
bluez-firmware - Firmware for Bluetooth devices
firmware-bnx2 - Binary firmware for Broadcom NetXtremeII
firmware-bnx2x - Binary firmware for Broadcom NetXtreme II 10Gb
firmware-crystalhd - Crystal HD Video Decoder (firmware)
firmware-misc-nonfree - Binary firmware for various drivers in the Linux kernel
firmware-brcm80211 - Binary firmware for Broadcom 802.11 wireless cards

This time it isn’t so easy to determine the correct firmware package as there are several possibilities, so we need to try something else. Listing the installed modules can help here – what you are looking for is a module that is used by ‘cfg80211’ (which is the configuration API for 802.11 devices).

lsmod
Module                  Size  Used by
brcmfmac              273230  0
brcmutil                9114  1 brcmfmac
cfg80211              542402  1 brcmfmac
rfkill                 21476  2 cfg80211
i2c_bcm2835             6465  0
uio_pdrv_genirq         3718  0
fixed                   3033  0
uio                     9901  1 uio_pdrv_genirq
i2c_dev                 6674  0
ip_tables              12427  0
x_tables               22130  1 ip_tables
ipv6                  397455  0

Then we can search for a firmware package using the name for that module.

apt-cache search brcmfmac
firmware-brcm80211 - Binary firmware for Broadcom 802.11 wireless cards

apt-get install firmware-brcm80211 --no-install-recommends
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  initramfs-tools
The following NEW packages will be installed:
  firmware-brcm80211
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 3672 kB of archives.
After this operation, 13.1 MB of additional disk space will be used.
  :
  :
  :
Setting up firmware-brcm80211 (1:20161130-3+rpt4) ...
 

Raspberry Pi 3 / 3+

lsusb
Bus 001 Device 004: ID 0424:7800 Standard Microsystems Corp. 
Bus 001 Device 003: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
Bus 001 Device 002: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Unfortunately searching the package database using the manufacturer’s name doesn’t always work.

apt-cache search "Standard Microsystems"

So you will have to see what you can find out by listing all the installed modules.

lsmod
Module                  Size  Used by
brcmfmac              307200  0
brcmutil               16384  1 brcmfmac
cfg80211              573440  1 brcmfmac
rfkill                 28672  2 cfg80211
i2c_bcm2835            16384  0
fixed                  16384  0
uio_pdrv_genirq        16384  0
uio                    20480  1 uio_pdrv_genirq
i2c_dev                16384  0
ip_tables              24576  0
x_tables               32768  1 ip_tables
ipv6                  425984  0

If you just read the section above then this will look very familiar!

apt-cache search brcmfmac
firmware-brcm80211 - Binary firmware for Broadcom 802.11 wireless cards

apt-get install firmware-brcm80211 --no-install-recommends
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  initramfs-tools
The following NEW packages will be installed:
  firmware-brcm80211
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 3672 kB of archives.
After this operation, 13.1 MB of additional disk space will be used.
  :
  :
  :
Setting up firmware-brcm80211 (1:20161130-3+rpt4) ...
 

Raspberry Pi 0 / W

In the unlikely event that you have to install the firmware on a Pi 0 W then you will find that it doesn’t give anything away. (When booting from a minimal installation that did not have any wireless components I found I could install the firmware on a Pi Zero W by connecting it to a USB hub with an ethernet interface to provide a wired network connection).

lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

However it shouldn’t come as any surprise that the list of installed modules looks familiar.

lsmod
Module                  Size  Used by
brcmfmac              307200  0
brcmutil               16384  1 brcmfmac
cfg80211              573440  1 brcmfmac
rfkill                 28672  2 cfg80211
i2c_bcm2835            16384  0
fixed                  16384  0
uio_pdrv_genirq        16384  0
uio                    20480  1 uio_pdrv_genirq
i2c_dev                16384  0
ip_tables              24576  0
x_tables               32768  1 ip_tables
ipv6                  425984  0

So we can just go ahead and install the firmware.

apt-get install firmware-brcm80211 --no-install-recommends
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  initramfs-tools
The following NEW packages will be installed:
  firmware-brcm80211
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 3672 kB of archives.
After this operation, 13.1 MB of additional disk space will be used.
  :
  :
  :
Setting up firmware-brcm80211 (1:20161130-3+rpt4) ...
 

Configuring the Wireless network

The first thing you need to do is install the wireless network tools, these will allow your Raspberry Pi to connect to your wireless access point.

apt-get install wireless-tools wpasupplicant --no-install-recommends
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libiw30 libnl-3-200 libnl-genl-3-200 libpcsclite1
Suggested packages:
  pcscd wpagui libengine-pkcs11-openssl
The following NEW packages will be installed:
  libiw30 libnl-3-200 libnl-genl-3-200 libpcsclite1 wireless-tools wpasupplicant
0 upgraded, 6 newly installed, 0 to remove and 2 not upgraded.
Need to get 974 kB/1047 kB of archives.
After this operation, 2670 kB of additional disk space will be used.
Do you want to continue? [Y/n] 
  :
  :
  :
Setting up wpasupplicant (2:2.4-1+deb9u2) ...
Processing triggers for libc-bin (2.24-11+deb9u3) ...
Processing triggers for dbus (1.10.26-0+deb9u1) ...
 

Now you need to reboot so you can check that you have installed the correct firmware.

reboot

If everything worked you should be able to view the wireless network interface, it won’t have an IP address yet but it should show up.

iwconfig
eth0      no wireless extensions.
 
lo        no wireless extensions.
 
wlan0     IEEE 802.11  ESSID:off/any  
          Mode:Managed  Access Point: Not-Associated   Tx-Power=0 dBm   
          Retry short  long limit:2   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:off

You can now configure the interface.

nano /etc/network/interfaces

/etc/network/interfaces
auto lo
iface lo inet loopback
 
allow-hotplug eth0
iface eth0 inet dhcp
 
auto wlan0
iface wlan0 inet dhcp
    wpa-ssid <Your SSID>
    wpa-psk <Your-PSK>

Note – If you are using one of the graphical desktops then there should be no entries in this file for either the wired or wireless network interface to allow you to configure them using network manager.

Finally you can check it works by trying to bring the interface up.

ifup wlan0
Internet Systems Consortium DHCP Client 4.3.5
Copyright 2004-2016 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
 
Listening on LPF/wlan0/00:87:23:80:8d:0e
Sending on   LPF/wlan0/00:87:23:80:8d:0e
Sending on   Socket/fallback
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 5
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 5
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 9
DHCPREQUEST of 192.168.0.130 on wlan0 to 255.255.255.255 port 67
DHCPOFFER of 192.168.0.130 from 192.168.0.1
DHCPACK of 192.168.0.130 from 192.168.0.1
bound to 192.168.0.130 -- renewal in 1599 seconds.

Note – Do NOT configure eth0 to use dhcp if the LAN cable isn’t going to be connected – otherwise the Raspberry Pi may hang for a while waiting for a DHCP address at boot.


Raspberry Pi is a trademark of the Raspberry Pi Foundation

Advertisements
This entry was posted in Networking, Raspbian and tagged , , , , . Bookmark the permalink.

4 Responses to Raspberry Pi Wireless Networking

  1. Tim Gormley says:

    Thanks1 This got my RPi3 successfully connected headless to wifi. Now I want to work on making it an AP (for extending my wifi reach) and using the ethernet connection to the network.

  2. Hi,
    Thanks for the detailed steps, I have tried all the steps you mentioned on my Raspberry PI 3 model (The device is having custom Linux build based on Jessie build) for bringing up wlan0 UP. But unfortunately, all the package and firmware installation leads to – “NO wlan0 in iwconfig result”

    Can you please tell me what exactly becoming wrong from my end and I am unable to get wlan0 interface up?

    Your help will be most appreciated. Thanks in advance :)

  3. Christine says:

    Hi Mike . Thank you for that. It’s solved a problem that has been bugging me for months. A project was on hold due to not being able to associate with my wireless router. Now it can go forward.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.