Disable Wifi when no Internet connection

I occasionally have problems with one of my children switching off a network device meaning that one of my 3 OpenWRT devices loses internet connection. This doesn't matter too much to me except that my mobile will sometimes switch to that device and lose connection (mid game sometimes!) - so I'd like to disable the Wifi interface on my OpenWRT device when it loses internet connection so that clients can no longer switch to that Wifi point.

You can probably keep mobile data on and not mess with the router

That's definitely not what I'm wanting. I want my mobile device to connect to the next nearest WiFi point, not to mobile data.

1 Like

are all 3 OpenWrt devices using a different internet connection?

No, they all use the same internet connection but are spread around the house, some wired directly and some with powerline

you can probably use the watchcat and luci-app-watchcat packages (to have also web interface to set it) in all the access points and set it to ping your main router IP and reboot the device if pings fail.
with function ping_reboot

Or you can edit the /usr/bin/watchcat.sh script to customize it more to do what you want. It's still easier than create everything from scratch.

Here is a script that will turn wifi on or off depending on successful ping to some IP address. Change the IP address and update time of your choice.

#!/bin/sh

while true; do
if ! ping -q -c 1 -W 1 8.8.8.8 >/dev/null; then
	if ifconfig | grep wlan >/dev/null; then
	wifi down
	fi
else
	if ! ifconfig | grep wlan >/dev/null; then
	wifi up
	fi
fi
sleep 10
done
1 Like

It is best not to ping all over the internet, as this can lead to false positives.
Instead, you can dynamically fetch the IP address of the WAN gateway.
Also send more than one probe to avoid triggering on a minor packet loss.

3 Likes