Skip to main content
1 of 3
Cray
  • 103
  • 3

Somehow the rest of the answers were still not satisfactory. There still doesn't seem to be a standard functionality (for such a basic function) which just works, or works with few extra settings, which also works in RPi 3 and up.

Then there are some scripts which either make things too complicated or need hardcoding addresses, or rely on custom assumptions. For example, what does it help to try pinging default route or 8.8.8.8, if the Wifi maybe is local-only? What if it doesn't set a default route at all? What if the default route is set on eth0 and is always available and wifi is used for other purposes? The question is "how to reconnect WiFi".

This is all you need:

#!/bin/bash SSID=$(/sbin/iwgetid --raw) if [ -z "$SSID" ] then sudo ifconfig wlan0 down sleep 30 sudo ifconfig wlan0 up fi echo "WiFi check finished" 

Just put that into autostart/cron as root and you're set. This solution is from https://gist.github.com/carry0987/372b9fefdd8041d0374f4e08fbf052b1 which has more details as well.

PS in case there is an obscure OS or RPi version, try using "ip link set wlan0 down / ip link set wlan0 up" instead of ifconfig ....

Cray
  • 103
  • 3