Wednesday 24 May 2017

Raspberry Pi - WiFi not working

I've recently had to investigate why the onboard WiFi connection on one of my Raspberry Pi V3 models wasn't working. I'm sure that this stopped working after an update but I cannot be certain. The following information only applies to the onboard WiFi on a Pi V3 - I don't need or require a separate USB WiFi dongle.

Troubleshooting turned out to be quite involved. I had tried to perform the usual commands of disabling and then re-enabling the WiFi interface (sudo ifdown wlan0 && sudo ifup wlan0) to no avail.

Reinstalled wpasupplicant package - still nothing. This action blatted my /etc/wpa_supplicant/wpa_supplicant.conf file so I recreated that from a working Raspberry Pi:

C3PI6:/run $ sudo cat /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=GB

network={
        ssid="Insert_your_WIFI_network_name_here"
        psk="Insert_your_WIFI_password_here"
        key_mgmt=WPA-PSK
}


My system tray icon resolutely refused to play ball and was showing the dreaded 'No wireless interfaces found'. Working from a Korn shell, I went back to basics and monitored the syslog output to see if I could work out where it was going wrong. After issuing the interface down command (sudo ifdown wlan0) I could see that I was getting an error about the lockfile state, or rather the lack of one. I saw that the directory of /run/network wasn't present so I created that. I created the lockfile by using the 'touch' command to simply touch the file and therefore create it:

C3PI6:/home/pi $ sudo ifdown wlan0
ifdown: failed to open lockfile /run/network/.ifstate.lock: No such file or directory
C3PI6:/home/pi $ sudo touch /run/network/.ifstate.lock
touch: cannot touch ‘/run/network/.ifstate.lock’: No such file or directory
C3PI6:/home/pi $ cd /run
C3PI6:/run $ cd network
-ksh93: cd: network: [No such file or directory]
C3PI6:/run $ sudo mkdir network
C3PI6:/run $ sudo touch /run/network/.ifstate.lock

C3PI6:/run $ sudo ifdown wlan0
ifdown: interface wlan0 not configured

C3PI6:/run $ sudo ifup wlan0
May 24 11:48:43 C3PI6 kernel: [  364.071977] brcmfmac: power management disabled
May 24 11:48:43 C3PI6 wpa_supplicant[2015]: Successfully initialized wpa_supplicant
May 24 11:48:44 C3PI6 wpa_supplicant[2018]: wlan0: CTRL-EVENT-REGDOM-CHANGE init=USER type=COUNTRY alpha2=GB
May 24 11:48:44 C3PI6 systemd[1]: Reloading OpenBSD Secure Shell server.
May 24 11:48:44 C3PI6 systemd[1]: Reloaded OpenBSD Secure Shell server.
May 24 11:48:44 C3PI6 wpa_supplicant[2018]: wlan0: Trying to associate with 00:24:a5:bc:2f:e5 (SSID='Johnnys_WIFI_working' freq=2447 MHz)
May 24 11:48:44 C3PI6 wpa_supplicant[2018]: wlan0: Associated with 00:24:a5:bc:2f:e5
May 24 11:48:44 C3PI6 wpa_supplicant[2018]: wlan0: WPA: Key negotiation completed with 00:24:a5:bc:2f:e5 [PTK=CCMP GTK=TKIP]
May 24 11:48:44 C3PI6 wpa_supplicant[2018]: wlan0: CTRL-EVENT-CONNECTED - Connection to 00:24:a5:bc:2f:e5 completed [id=0 id_str=]
May 24 11:48:44 C3PI6 dhcpcd[384]: wlan0: carrier acquired
May 24 11:48:44 C3PI6 dhcpcd[384]: wlan0: IAID eb:9b:ad:32
May 24 11:48:45 C3PI6 dhcpcd[384]: wlan0: soliciting a DHCP lease
May 24 11:48:45 C3PI6 dhcpcd[384]: wlan0: offered 192.168.1.106 from 192.168.1.1
May 24 11:48:45 C3PI6 dhcpcd[384]: wlan0: soliciting an IPv6 router
May 24 11:48:50 C3PI6 dhcpcd[384]: wlan0: leased 192.168.1.106 for 86400 seconds
May 24 11:48:50 C3PI6 avahi-daemon[379]: Joining mDNS multicast group on interface wlan0.IPv4 with address 192.168.1.106.
May 24 11:48:50 C3PI6 avahi-daemon[379]: New relevant interface wlan0.IPv4 for mDNS.
May 24 11:48:50 C3PI6 dhcpcd[384]: wlan0: adding route to 192.168.1.0/24
May 24 11:48:50 C3PI6 avahi-daemon[379]: Registering new address record for 192.168.1.106 on wlan0.IPv4.
May 24 11:48:50 C3PI6 dhcpcd[384]: wlan0: adding default route via 192.168.1.1
May 24 11:48:52 C3PI6 ntpd[611]: Listen normally on 4 wlan0 192.168.1.106 UDP 123
May 24 11:48:52 C3PI6 ntpd[611]: peers refreshed

As you can see from the above, my WiFi is now working on IP 192.168.1.106 and I can therefore disconnect the Ethernet cable as this Pi runs headless and wireless.

Please note - check that you have the following packages installed, and if not, install them: wireless-regdb, crda, iw

The eagle-eyed amongst you will have noted that I have turned off power-management of the WiFi interface as this can cause problems/instability. I have included a copy of the file that is located at /etc/network/interfaces:

C3PI6:/var/log/apt $ cat /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 manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
wireless-power off

Note - the last line/entry shows the power management switched off.

Tuesday 7 February 2017

Raspberry Pi V1 - Wheezy vs Jessie

I've had many Raspberry Pi computers, with most of them being either V2 or V3 but I do have one of the original version 1 Pi computers - this one has only 512MB of RAM and a single core/processor. Whilst in the process of reallocation of duties, I decided to set this one up in 'Kiosk mode' so that I can display the webcam output from one of my more powerful Pi3 computers.

I hit loads of problems with trying to get motion working as it all seems to be geared towards the Jessie release, and my Pi1 was running Wheezy. I thought that it would be good to go back to square one and start afresh. I went to search on the internet to find a download site for the Wheezy image of Raspbian and hit a problem as the Raspberry Pi website only lists current releases i.e. Jessie and that won't work with mine as it's armhf as opposed to armv6l

Anyways, long story short and all that. After much searching, I came across this URL after trwaling through the forums:

Raspberry Pi V1 Wheezy image
.
https://downloads.raspberrypi.org/raspbian/images/raspbian-2015-05-07/

Hope this helps.