Skip to content

Instantly share code, notes, and snippets.

@jacobpretorius
Created April 18, 2021 11:22
Show Gist options
  • Save jacobpretorius/1c479ec38e8021196215fd2e9ae74675 to your computer and use it in GitHub Desktop.
Save jacobpretorius/1c479ec38e8021196215fd2e9ae74675 to your computer and use it in GitHub Desktop.
Raspberry Pi OS (2021) Automatically reconnect to wifi when connection drops

Raspberry Pi OS (2021) Automatically reconnect to wifi when connection drops

I've been having a few wifi drops and then the pi doesn't reconnect until I reboot it manually. This script solves that.

First, add a new sudo cron

sudo crontab -e

Then adapt and paste the following, change the IP to that of your router or something you expect to be always up

*/5 * * * * /bin/ping -q -c10 192.168.8.1 > /dev/null 2>&1 || (ip link set dev wlan0 down ;ip link set dev wlan0 up ;/usr/bin/logger wifi on wlan0 restarted via crontab)

That's all :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment