Skip to content

Instantly share code, notes, and snippets.

@oofnikj
Created December 27, 2019 21:48
Show Gist options
  • Save oofnikj/9b653e58d1f887fc166b7eb700e327b6 to your computer and use it in GitHub Desktop.
Save oofnikj/9b653e58d1f887fc166b7eb700e327b6 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Script to reset wifi on a Raspberry Pi Zero W
# Outputs a message to systemd-journal every time it resets
#
# nothing else seemed to work
#
# Run it with crontab every minute
GATEWAY_IP=$(/sbin/ip -4 route | grep default | awk '{print $3}')
_am_i_online() {
ping -D -c3 $GATEWAY_IP
}
_fix_it() {
echo "can't reach gateway! unloading / reloading wifi kernel module" | systemd-cat -t $(basename $0)
# shutdown -r
/sbin/modprobe -r brcmfmac
/sbin/modprobe brcmfmac
}
_am_i_online || _fix_it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment