Setup WiFi on a Raspberry Pi 3 with Raspbian Jessie

Getting the WiFi to connect via the command line can be a real pain, especially with the numerous out-of-date guides and lack of feedback during the connection phase. The following guide covers some tips and tricks I have found.

Note: Ignore all other guides which change anything in the /etc/network/interfaces file, these are out-of-date and do not apply to Raspbian Jessie. If you have made any changes to this file revert them back to how it was.

Setup and Connect

	
		# scan for wifi networks in range, this will list (amongst many things) the SSID and encryption type
		sudo iwlist wlan0 scan
		#wlan0     Scan completed :
		#...
		#
		# if the network has a password required to connect then this will need to be entered into the wpa_supplicant config file
		sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
	
	
		country=GB
		ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
		update_config=1
		network={
		    ssid="your ssid"
		    psk="your network password"
		}
		# fill in as many network={} blocks as required
		# more advance config options may be found on the man page
	
	
		# bring the network down and then up to test connecting
		sudo ifdown wlan0
		sudo ifup wlan0
		
		# view the output of ifconfig, if an IPv4 address is shown next to inet addr: then the connection has worked
		ifconfig wlan0
		#wlan0     Link encap:Ethernet  HWaddr 00:00:00:00:00:00
		#          inet addr:192.168.0.45  Bcast:192.168.0.255  Mask:255.255.255.0
		#          inet6 addr: 0000::0000:0000:0000:0000/64 Scope:Link
		#          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
		#          RX packets:11124 errors:0 dropped:3702 overruns:0 frame:0
		#          TX packets:894 errors:0 dropped:0 overruns:0 carrier:0
		#          collisions:0 txqueuelen:1000
		#          RX bytes:1257735 (1.1 MiB)  TX bytes:181713 (177.4 KiB)
	

Troubleshoot

If the connection has not worked the preceding commands unfortunately give no feedback as to what is going on or why this may be. Conveniently wpa comes with its own cli client which can be used to troubleshoot any issues.

	
		sudo wpa_cli
		#wpa_cli v2.3
		#Selected interface 'wlan0'
		#Interactive mode
		#
		# list any networks found in the wpa_supplicant config
		> list_networks
		#network id / ssid / bssid / flags
		#0       SSID1 any
		#1       SSID2        any     [CURRENT]
		#
		# reloads the latest copy of the wpa_supplicant config file and displays feedback as it attempts to connect
		# in the following output I show an unsuccessful attempt to connect to SSID1 due to an incorrect password, followed by a success connecting to SSID2
		> reconfigure
		#OK
		#<3>CTRL-EVENT-DISCONNECTED bssid=00:00:00:00:00:00 reason=3 locally_generated=1
		#<3>CTRL-EVENT-SCAN-STARTED
		#<3>CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
		#<3>CTRL-EVENT-REGDOM-CHANGE init=USER type=COUNTRY alpha2=GB
		#<3>CTRL-EVENT-SCAN-RESULTS
		#<3>Trying to associate with 00:00:00:00:00:00 (SSID='NETGEAR' freq=2437 MHz)
		#<3>Associated with 00:00:00:00:00:00
		#<3>CTRL-EVENT-DISCONNECTED bssid=00:00:00:00:00:00 reason=0 locally_generated=1
		#<3>WPA: 4-Way Handshake failed - pre-shared key may be incorrect
		#<3>CTRL-EVENT-SSID-TEMP-DISABLED id=0 ssid="SSID1" auth_failures=1 duration=10 reason=WRONG_KEY
		#<3>CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
		#<3>CTRL-EVENT-REGDOM-CHANGE init=USER type=COUNTRY alpha2=GB
		#<3>CTRL-EVENT-SCAN-STARTED
		#<3>CTRL-EVENT-SCAN-RESULTS
		#<3>Trying to associate with 11:11:11:11:11:11 (SSID='SSID2' freq=2472 MHz)
		#<3>Associated with 11:11:11:11:11:11
		#<3>WPA: Key negotiation completed with 11:11:11:11:11:11 [PTK=CCMP GTK=TKIP]
		#<3>CTRL-EVENT-CONNECTED - Connection to 11:11:11:11:11:11 completed [id=1 id_str=]
		#<3>CTRL-EVENT-REGDOM-CHANGE init=COUNTRY_IE type=COUNTRY alpha2=GB
		#
		# shows the connection status
		> status
		#bssid=11:11:11:11:11:11
		#freq=2472
		#ssid=SSID2
		#id=1
		#mode=station
		#pairwise_cipher=CCMP
		#group_cipher=TKIP
		#key_mgmt=WPA-PSK
		#wpa_state=COMPLETED
		#ip_address=192.168.0.45
		#p2p_device_address=11:11:11:11:11:11
		#address=11:11:11:11:11:11
		#uuid=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
		#
		# exits the cli
		> quit
	

For more advance options consult the man page

Load Comments...