Raspberry Pi/Wifi Auto Restart: Difference between revisions

From Wiki
No edit summary
Line 14: Line 14:
check_interval=60
check_interval=60
router_ip=192.168.111.1
router_ip=192.168.111.1
log=/var/log/wifi.log.
log=/var/log/wifi.log


# make sure we aren't running already
# make sure we aren't running already
Line 23: Line 23:
         fi
         fi
done
done


# log settings
# log settings
Line 29: Line 28:
exec 2>> $log
exec 2>> $log
echo $(date) > $log
echo $(date) > $log


startWifi () {
startWifi () {
         #dhclient -v -r
         echo $(date)" attempting restart..." >> $log
        # make really sure
         ifdown wlan0
        #killall dhclient
         ifup wlan0
        #iwconfig $wlan essid $essid
        #dhclient -v $wlan
 
        echo "restarting"
         #ifdown wlan0
         #ifup wlan0
}
}


while [ 1 ]; do
while [ 1 ]; do
         ping -c 1 $router_ip & wait $!
         ping -c 1 $router_ip & wait $!
         if [ $? != 0 ]; then
         if [ $? != 0 ]; then
                echo $(date)" attempting restart..." >> $log
                 startWifi
                 startWifi
                 sleep 1
                 sleep 1

Revision as of 15:12, 15 April 2017

Requirements

  • /etc/network/interfaces
allow-hotplug wlan0
iface wlan0 inet dhcp
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf


Watchdog script

  • /srv/scripts/wifi_watchdog.sh
#!/bin/bash
check_interval=60
router_ip=192.168.111.1
log=/var/log/wifi.log

# make sure we aren't running already
what=`basename $0`
for p in `ps h -o pid -C $what`; do
        if [ $p != $$ ]; then
                exit 0
        fi
done

# log settings
exec 1> /dev/null
exec 2>> $log
echo $(date) > $log

startWifi () {
        echo $(date)" attempting restart..." >> $log
        ifdown wlan0
        ifup wlan0
}

while [ 1 ]; do
        ping -c 1 $router_ip & wait $!
        if [ $? != 0 ]; then
                startWifi
                sleep 1
        else sleep $check_interval
        fi
done