Auto reconnect WiFi after AP (router) drops

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 -

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
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?

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):

while true

	#check connection
	#	change 192.xxxx to your router IP address
	if (( $(ping -c 1 != 0 )); then
		# - reconnect
		ifdown wlan0
		ifup wlan0
		# - wait 60 seconds before checking again
		sleep 60

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? :slight_smile: