Wifi

Sometimes wifi connectivity is lost, following scripts tries to restore connection and reboots if connection could not be restored otherwise.

Filename: reset_wifi.bash

 
#!/bin/bash
 
cd /home/pi/wifi
 
DATE=$(date +%d-%b-%Y+%H:%M)
 
ping -c4 192.168.178.1
 
if [ $? != 0 ]
then
    echo "connection lost "$DATE >> wifi.log
    /sbin/ifdown wlan0
    sleep 5
    /sbin/ifup --force wlan0
    sleep 5
    ping -c4 192.168.178.1
    if [ $? != 0 ]; then
        echo "REBOOT "$DATE >>  wifi.log
        sudo reboot
    fi
else
   echo "network is up"
 
fi

The next script copies the tail of the logfile to a website reboot.html.
Filename: wf3.bash

#!/bin/bash
cd /home/pi/wifi
DATE=`date +%d-%b-%Y`
HEAD="<HTML><BODY><TITLE>Reboot-log </TITLE><H1>Reboot-log "$DATE" Den Haag</H1><pre>"
BODY=`tail wifi.log`
FOOT="<\/pre></BODY></HTML>" # please remove the "\" before /pre
echo $HEAD"$BODY"$FOOT > reboot.html
cp reboot.html /var/www/html

Add to your crontab:

sudo crontab -e
*/15 * * * * /home/pi/wifi/./reset_wifi.bash
@daily /home/pi/wifi/./wf3.bash