Wifi on the Raspberry Pi

Had a few requests about this and there are various answers on forums around the place, but this is how I did it using a PI Hut dongle:

sudo apt-get update
sudo apt-get upgrade
sudo shutdown -r 0

Those three commands make sure everything is the latest it needs to be before you try anything else. Now let’s edit two files:
sudo nano /etc/network/interfaces

# just add or edit the wlan sections at the bottom, leave the rest of the file as you find it
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

#This is the entire file and it gets me onto my home wifi network, but change the ssid and the psk to the password for your network
ctrl_interface=DIR=/var/run/wpa_supplicant
GROUP=netdev
update_config=1
network={ ssid="59KnightsWay" psk="afafafafafa" }

 
Note: If you wanted a static wifi address, the interfaces file needs a minor tweak:

allow-hotplug wlan0
iface wlan0 inet static
address 192.168.1.99
netmask 255.255.255.0
gateway 192.168.1.1
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Reboot and use these two commands to check what did and didn’t work:
ifconfig wlan0
tail -500 /var/log/syslog | grep wlan
If you struggle with wpa_supplicant, you can wimp out and do it all in /etc/network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
iface eth0 inet manual
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.1.99
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8
wpa-ssid "MySSID"
wpa-psk "mypassword"