FlashT
Posts: 64
Joined: Fri Jul 24, 2015 3:51 pm

[Solved] RPi3 WiFi won't reconnect

Sun Dec 04, 2016 1:03 pm

I configured the WiFi based on this article:

https://www.raspberrypi.org/documentati ... ess-cli.md

But it seems that it works only exactly after reboot. But when something goes wrong (for example I will reboot the router, or simply disconnect because of temporally bad signal), the WiFi is not being reconnected. Never.

Why? How can I fix that?

PS. The other thing is that ifdown and ifup doesn't help at all... only reboot.

---

Found a partially working solution:

Just edit networking file wlan0 section so it would look like this:

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

EDIT: Don't use it! It somehow ruins Ethernet connection! Solution HERE.
Last edited by FlashT on Mon Dec 05, 2016 10:18 pm, edited 2 times in total.

FlashT
Posts: 64
Joined: Fri Jul 24, 2015 3:51 pm

Re: [NOT Solved] RPi3 WiFi won't reconnect

Mon Dec 05, 2016 2:14 am

But that only works, when WIFI is available on boot... I just had a case that power was down, and RPi started before modem... It never connected.

User avatar
pi-anazazi
Posts: 716
Joined: Fri Feb 13, 2015 9:22 pm
Location: EU

Re: [NOT Solved] RPi3 WiFi won't reconnect

Mon Dec 05, 2016 7:37 am

Dunno if related: I have the same with raspian and wired connection. Never reconnecting after loss of initial network connection.

Only helpful reply on this forum: Do a fresh install...
Kind regards

anazazi

FlashT
Posts: 64
Joined: Fri Jul 24, 2015 3:51 pm

Re: [NOT Solved] RPi3 WiFi won't reconnect

Mon Dec 05, 2016 7:23 pm

My first solution (the partially working one) seems to affect ethernet ... somehow Apache stops responding on Ethernet. So it's not a good solution, when using both ETH0 and WLAN0 ...

I wrote some simple reconnect script and put it into root crontab on reboot... someone may be interested:

Code: Select all

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

echo `date "+%Y-%m-%d %H:%M:%S" | tr -d '\n'` "Reconnection script started."
sleep 10

while true
do
    if ! ifconfig | grep --quiet "192.168.2."; then
	echo `date "+%Y-%m-%d %H:%M:%S" | tr -d '\n'` "Not connected, checking if LAN3 network is available..."
	if iwlist wlan0 scan | grep --quiet "LAN3"; then
	    echo `date "+%Y-%m-%d %H:%M:%S" | tr -d '\n'` "Network is available! Restarting WLAN..."
	    ifconfig wlan0 down > /dev/null
	    sleep 1
	    ifconfig wlan0 up > /dev/null
	    sleep 10
	    if ifconfig | grep --quiet "192.168.2."; then
		echo `date "+%Y-%m-%d %H:%M:%S" | tr -d '\n'` "Reconnection successful!"
	    else
		echo `date "+%Y-%m-%d %H:%M:%S" | tr -d '\n'` "Reconnection failed!"
	    fi
	else
	    echo `date "+%Y-%m-%d %H:%M:%S" | tr -d '\n'` "Network is not available... going to sleep for 20s."
	    sleep 20
	fi
    fi
    sleep 10
done
Root crontab:

Code: Select all

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

@reboot /bin/bash /home/sigma/wifi/reconnect.sh >> /var/log/wifi_reconnect.log
Example log:

Code: Select all

2016-12-05 19:17:03 Reconnection script started.
2016-12-05 19:17:13 Not connected, checking if LAN3 network is available...
2016-12-05 19:17:14 Network is not available... going to sleep for 20s.
2016-12-05 20:06:48 Not connected, checking if LAN3 network is available...
2016-12-05 20:06:48 Network is not available... going to sleep for 20s.
2016-12-05 20:07:18 Not connected, checking if LAN3 network is available...
2016-12-05 20:07:19 Network is not available... going to sleep for 20s.
2016-12-05 20:07:49 Not connected, checking if LAN3 network is available...
2016-12-05 20:07:50 Network is available! Restarting WLAN...
2016-12-05 20:08:01 Reconnection failed! // <- failed, because WLAN on router was up, but yet not accepting connections.
2016-12-05 20:08:11 Not connected, checking if LAN3 network is available...
2016-12-05 20:08:12 Network is available! Restarting WLAN...
2016-12-05 20:08:24 Reconnection successful!
May be worth to work with times...

Please note that you have to change ip class and network name to make it work for ya. What it does is ... it checks if you are connected, if not, it checks if network is available, if yes it tries to reconnect. As simple as that.

Return to “Troubleshooting”