I am trying to find a way to check and if needed restart my WiFi since it keeps stalling every couple of days.
Therefore I want to write a shell script that runs on the router and pings a WiFi connected device (ESP8266 that is running 24/7 anyways) every minute and if this fails it should restart the WiFi of the router.
Does anyone know how to restart WiFi with a CLI command?
I have three devices that are always connected that I can ping to this should be pretty safe.
That's what worked for my setup with radio1 and a logfile:
#!/bin/sh
while true
do
if echo $(ping -W 2 -c 1 192.168.8.11) |grep ', 0%' &>/dev/null
then
nichtda=0
elif echo $(ping -W 2 -c 1 192.168.8.10) |grep ', 0%' &>/dev/null
then
nichtda=0
elif echo $(ping -W 2 -c 1 192.168.8.12) |grep ', 0%' &>/dev/null
then
nichtda=0
else
echo "WiFi down"
nichtda=$((nichtda + 1))
fi
if test $nichtda -gt 2
then
date +"%D - %T" >> /var/log/wifirestartlog
uci set wireless.radio1.disabled='1'
uci commit
sleep 2
wifi down radio1
sleep 10
uci set wireless.radio1.disabled='0'
uci commit
sleep 2
wifi up radio1
nichtda=0
sleep 600
fi
sleep 60
done