de_a
Posts: 6
Joined: Thu Jul 23, 2015 12:21 pm

Wi-Fi connection fell during holidays, never went back up

Thu Jul 23, 2015 12:38 pm

Hi!

I have a problem that is really puzzling me. My Pi is almost always running, and equipped with a RTL8191SU 802.11n WLAN Adapter adapter. It is headless, so I have to ssh into it for all maintenance tasks.

Last week I went on holidays, and turned off my router/AP, but forgot to turn off the Pi. I have a script called keepalive.sh, which is running as a service, and tries to maintain connection at all costs. Here it is:

Code: Select all

while [ 1 ]
        do
        sleep 5;
        c=$(ping -c1 192.168.0.1 | grep -m1 "1 received")
        if [ -z "$c" ]
        then
                # problem, router is not responding.
                echo $(date) - Wifi down. Attempting redhcpcd. >> /var/log/router.log
                dhclient -r wlan0 >> /var/log/router.log
                dhclient wlan0 >> /var/log/router.log
                sleep 15
                c=$(ping -c1 192.168.0.1 | grep -m1 "1 received")
                if [ -z "$c" ]
                then
                        echo $(date) - first attempt failed. Attempting ifdown. >> /var/log/router.log
                        ifdown wlan0
                        sleep 5
                        ifup --force wlan0
                        sleep 20
                        c=$(ping -c1 192.168.0.1 | grep -m1 "1 received")
                        if [ -z "$c" ]
                        then
                                echo $(date) - second attempt failed. Rebooting. >> /var/log/router.log
                                shutdown -r now
                        fi
                fi
        fi
        done

So basically, the Pi went through a series of many, may reboots in the last week. Now no matter what I do, I can't seem to connect to my WiFi network anymore. Ethernet works fine, even the WiFi seems okay in general, since I managed to connect to an open network. But the network I am usually connecting to remains unreachable. Here is my interfaces file:

Code: Select all

auto lo eth0 wlan0

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet static
address 192.168.0.5
netmask 255.255.255.0
gateway 192.168.0.1
wireless-essid Fomalhaut_closed
#wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
pre-up wpa_supplicant -B w -D wext -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
post-down killall -q wpa_supplicant
iface default inet dhcp
and here is my wpa_supplicant conf file

Code: Select all

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
	ssid="Fomalhaut_closed"
	psk=<contains the correct hash>
	proto=RSN
	key_mgmt=WPA-PSK
	group=CCMP TKIP
}
When I use iwconfig, I get:

Code: Select all

wlan0     unassociated  Nickname:"rtl_wifi"
          Mode:Managed  Access Point: Not-Associated   Sensitivity:0/0  
          Retry:off   RTS thr:off   Fragment thr:off
          Power Management:off
          Link Quality:0  Signal level:0  Noise level:0
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0
In other words, I cannot associate to my AP anymore.
At some point as I said I tried adding an open network in wpa_supplicant.conf, and managed to connect by doing

Code: Select all

sudo iwconfig wlan0 mode Managed essid "my_ssid"
WPA_supplicant is running, as ps confirms:

Code: Select all

root      1505  0.0  0.2   5968   952 ?        Ss   13:31   0:00 wpa_supplicant -B w -D wext -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
when I try to restart wlan0 by doing

Code: Select all

sudo wpa_cli -i wlan0 terminate
sudo ifup --force wlan0
I get the message

Code: Select all

rfkill: Cannot open RFKILL control device
RTNETLINK answers: File exists
Failed to bring up wlan0.
I tried releasing the leases to no avail, and ip route does not contain any route for wlan0.
Does this make sense to anyone? I have spent a great amount of time on this issue and so far, everything has failed.

Thanks,

de_a

de_a
Posts: 6
Joined: Thu Jul 23, 2015 12:21 pm

Re: Wi-Fi connection fell during holidays, never went back u

Thu Jul 23, 2015 4:21 pm

An update: I found out that replacing static by dhcp in the interfaces file worked fine; the Pi manages to fetch a dynamic address.

However, it is primordial that the Pi gets a static address. I manage to get some kind of result on that front by commenting the gateway line in the interfaces file:

Code: Select all

#gateway 192.168.0.1
this way, I can get my static ip:

Code: Select all

wlan0     IEEE 802.11bgn  ESSID:"Fomalhaut_closed_u"  Nickname:"rtl_wifi"
          Mode:Managed  Frequency:2.432 GHz  Access Point: 30:B5:C2:4F:67:DD   
          Bit Rate:150 Mb/s   Sensitivity:0/0  
          Retry:off   RTS thr:off   Fragment thr:off
          Power Management:off
          Link Quality=100/100  Signal level=100/100  Noise level=0/100
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

[email protected] ~ $ ifconfig wlan0
wlan0     Link encap:Ethernet  HWaddr 24:05:0f:27:00:e6  
          inet adr:192.168.0.5  Bcast:192.168.0.255  Masque:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:285 errors:0 dropped:74 overruns:0 frame:0
          TX packets:129 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 lg file transmission:1000 
          RX bytes:34397 (33.5 KiB)  TX bytes:22001 (21.4 KiB)

However, there is no internet connection. ping google.com produces a "network unreachable" error. Almost there?

de_a
Posts: 6
Joined: Thu Jul 23, 2015 12:21 pm

Re: Wi-Fi connection fell during holidays, never went back u

Thu Jul 23, 2015 9:23 pm

I had a feeling that there was something wrong with the routing table.
So I added a route manually, copying the one I was seeing when eth0 was plugged in:

Code: Select all

[email protected] ~ $ sudo route add -net default gw 192.168.0.1 dev wlan0
[email protected] ~ $ route
Table de routage IP du noyau
Destination     Passerelle      Genmask         Indic Metric Ref    Use Iface
default         192.168.0.1     0.0.0.0         UG    0      0        0 wlan0
link-local      *               255.255.0.0     U     0      0        0 eth0
192.168.0.0     *               255.255.255.0   U     0      0        0 wlan0
Now, I have access to the internet. The mask I have set here is wrong, as it should be 255.255.255.0, but when I add "netmask 255.255.255.0" to the route add command, I lose internet connection. Why only the wrong mask is working is beyond me.
So the problem is technically solved, or at least I've found a workaround. But 1) I don't know how to make this route persistent after reboot, and 2) I would still very much like to know why this is not dealt with automatically as with eth0 or wlan0+dhcp, so as to fix this properly and avoid doing patchy things.

Return to “Troubleshooting”