Skip to content

Instantly share code, notes, and snippets.

@draptik
Last active December 21, 2021 17:16
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save draptik/9f4b472da9f315aeeb3b to your computer and use it in GitHub Desktop.
Save draptik/9f4b472da9f315aeeb3b to your computer and use it in GitHub Desktop.
crontab -e
*/5 * * * * /usr/bin/sudo -H /home/pi/my-scripts/checkwifi.sh >> /dev/null 2>&1
# http://weworkweplay.com/play/rebooting-the-raspberry-pi-when-it-loses-wireless-connection-wifi/
# Check wifi connection...
ping -c4 192.168.179.3 > /dev/null
# '$?' is the exit code of previous ping command.
# If exit code != 0 (failure)...
if [ $? != 0 ]
then
echo "$(date): No network connection, restarting wlan0" >> /var/log/checkwifi.log
# deactivate wifi...
/sbin/ifdown 'wlan0'
sleep 5
# Restart wifi...
/sbin/ifup --force 'wlan0'
fi
@DrDeath
Copy link

DrDeath commented Jun 18, 2021

# deactivate wifi...
ip link set wlan0 down
sleep 5
# Restart wifi...
ip link set wlan0 up

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