Auto reconnect WiFi after AP (router) drops

Having issues with your DietPi installation, or, found a bug? Post it here.
Post Reply
subaquatic
Posts: 12
Joined: Sat Nov 28, 2015 7:25 pm

Auto reconnect WiFi after AP (router) drops

Post by subaquatic »

I recently switched to Wifi from a USB-Ethernet adapter on a PiZero. Unfortunately, it will not reconnect if the AP drops. It looks like exactly the same problem in this ticket - https://github.com/Fourdee/DietPi/issues/396

and I made the adjustments recommended from the stackexchange post:
Go to /etc/ifplugd/action.d/ and rename the ifupdown file to ifupdown.original
Then do: cp /etc/wpa_supplicant/ifupdown.sh ./ifupdown
Finally: sudo reboot
That's all. Test this by turning off/on your AP; you should see that your Raspberry Pi properly reconnects.
It still doesn't reconnect unless unplug/replug the usb-wifi adapter or reboot the Pi Zero.

Any ideas?
Last edited by subaquatic on Thu Oct 20, 2016 4:03 pm, edited 1 time in total.
subaquatic
Posts: 12
Joined: Sat Nov 28, 2015 7:25 pm

Re: Auto reconnect WiFi after AP (router) drops

Post by subaquatic »

Set the Wifi country and it started working

**EDIT - I spoke to soon. Still does not reconnect wifi after it drops. I've tried with different adapters, same problem. Interestngly, I have a B+ running dietpi and it reconnects just fine.
User avatar
Fourdee
Site Admin
Posts: 2788
Joined: Tue Feb 06, 2007 1:36 pm

Re: Auto reconnect WiFi after AP (router) drops

Post by Fourdee »

subaquatic wrote:Set the Wifi country and it started working

**EDIT - I spoke to soon. Still does not reconnect wifi after it drops. I've tried with different adapters, same problem. Interestngly, I have a B+ running dietpi and it reconnects just fine.
Yep expected results.

If the device is unplugged and plugged back in, the kernel will detect a hotplug event and automatically try to reconnect.
As for when the router WiFi drops, you'd need to make a script that monitors and checks for connection drops, to bring down and up the adapter.

So you could do something along the lines of (untested):

Code: Select all

#!/bin/bash
while true
do

	#check connection
	#	change 192.xxxx to your router IP address
	if (( $(ping -c 1 192.168.0.1) != 0 )); then
	
		# - reconnect
		ifdown wlan0
		ifup wlan0
		
		# - wait 60 seconds before checking again
		sleep 60
	
	fi
	
done
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
bor.greiner
Posts: 4
Joined: Wed Dec 14, 2016 11:02 pm

Re: Auto reconnect WiFi after AP (router) drops

Post by bor.greiner »

I was looking for an answer to just this question... Erm... Can anyone tell me how do I make this script and where do I save it? :)
Post Reply