I had some issues with the Pi locking up, or the WiFi connection being dropped. So I have added a cron job to check the WiFi link, and also enabled the watchdog timer on the Raspberry Pi to check for a complete lock up.
WiFi Ping Test
for the Wifi part I did the following using this guide:
Create a bash script to check ping on the wlan0 network:
> sudo nano /usr/local/bin/checkwifiping.sh
Add the following to the script:
Now I added this to the sudo crontab, as follows:
> sudo crontab -e
adding the following line:
*/2 * * * * /usr/bin/sudo -H /usr/local/bin/checkwifiping.sh >> /home/pi/log/cron.log
This tells cron to run the script every 2 minutes, and log output to the file /home/pi/log/cron.log, so we need to add the log directory to the home directory:
> mkdir /home/pi/log
Now if the WiFi is reset a log is made within this file, also when you are testing the operation some of the echo commands can be un-commented in the checkwifiping.sh script so you can see more debug stuff!
Watchdog Timer
I followed this guide on Ricoardo's Workbench
Once configured as per the guide, the watchdog timer checks the load on the system, and if it is greater than 25 pi's would take to execute in one minute, then it resets the system. I have not checked this is working.. Now you can also add a ping test within the watchdog, however, it happens every 10 seconds, and I don't really want to reset the system if the WiFi goes down, hence I left it in the cron job. I believe the watchdog can be set to a maximum of 15 seconds on the Pi.
WiFi Ping Test
for the Wifi part I did the following using this guide:
Create a bash script to check ping on the wlan0 network:
> sudo nano /usr/local/bin/checkwifiping.sh
Add the following to the script:
This script gets the default gateway address and pings it, if there is no reply then the wlan0 interface is reset.#!/bin/bash# find the router gateway to pingIP=$(/sbin/ip route | awk '/default/ { print $3 }')#echo $IP#interface to checkiface='wlan0'#echo "Starting ping test on $iface"#date#ping -c4 -I $iface 192.168.0.1 > /dev/nullping -c4 -I $iface $IP > /dev/nullif [ $? != 0 ]thendateecho "Ping test on $iface to $IP FAILED! Resetting $iface"sudo ifdown $ifacesudo ifup $ifaceecho "Done"echofi
Now I added this to the sudo crontab, as follows:
> sudo crontab -e
adding the following line:
*/2 * * * * /usr/bin/sudo -H /usr/local/bin/checkwifiping.sh >> /home/pi/log/cron.log
This tells cron to run the script every 2 minutes, and log output to the file /home/pi/log/cron.log, so we need to add the log directory to the home directory:
> mkdir /home/pi/log
Now if the WiFi is reset a log is made within this file, also when you are testing the operation some of the echo commands can be un-commented in the checkwifiping.sh script so you can see more debug stuff!
Watchdog Timer
I followed this guide on Ricoardo's Workbench
Once configured as per the guide, the watchdog timer checks the load on the system, and if it is greater than 25 pi's would take to execute in one minute, then it resets the system. I have not checked this is working.. Now you can also add a ping test within the watchdog, however, it happens every 10 seconds, and I don't really want to reset the system if the WiFi goes down, hence I left it in the cron job. I believe the watchdog can be set to a maximum of 15 seconds on the Pi.