Raspberry Pi/Wifi Auto Restart: Difference between revisions
(Die Seite wurde neu angelegt: „== Requirements == * /etc/network/interfaces <pre> allow-hotplug wlan0 iface wlan0 inet dhcp wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf </pre>“) |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
iface wlan0 inet dhcp | iface wlan0 inet dhcp | ||
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf | wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf | ||
</pre> | |||
== Watchdog script == | |||
* /srv/scripts/wifi_watchdog.sh | |||
<pre> | |||
#!/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 | |||
# wifi restart commands | |||
startWifi () { | |||
echo $(date)" attempting restart..." >> $log | |||
ifdown wlan0 | |||
ifup wlan0 | |||
sleep 1 | |||
} | |||
# check loop | |||
while [ 1 ]; do | |||
ping -c 1 $router_ip & wait $! | |||
if [ $? != 0 ]; then | |||
startWifi | |||
else sleep $check_interval | |||
fi | |||
done | |||
</pre> | </pre> |
Latest revision as of 15:13, 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 # wifi restart commands startWifi () { echo $(date)" attempting restart..." >> $log ifdown wlan0 ifup wlan0 sleep 1 } # check loop while [ 1 ]; do ping -c 1 $router_ip & wait $! if [ $? != 0 ]; then startWifi else sleep $check_interval fi done