Thursday, 2 June 2016

TAZ 5 OcotPrint on Raspberry Pi keeping it running

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/

Add the following to the script:

# find the router gateway to ping
IP=$(/sbin/ip route | awk '/default/ { print $3 }')
#echo $IP
#interface to check
#echo "Starting ping test on $iface"
#ping -c4 -I $iface > /dev/null
ping -c4 -I $iface $IP > /dev/null
if [ $? != 0 ]
  echo "Ping test on $iface to $IP FAILED!  Resetting $iface"
  sudo ifdown $iface
  sudo ifup $iface
  echo "Done"
This script gets the default gateway address and pings it, if there is no reply then the wlan0 interface is reset.

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/ >> /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 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.

Pi Camera TAZ 5

I want to keep the raspberry Pi outside of the cabinet so that the panel is accessible, and to keep it out if the heat! In order to do this I needed to extend the camera. I found this great HDMI extension kit, works well and makes camera positioning much easier!

TAZ 5 OctoPrint in Pi

I have taken the OctoPiPanel code and tweaked it for my use. It's a great idea to have some visual feedback and control on the Pi tft screen, but I wanted to make some changes to the default code. I have made the buttons and text larger, and removed a couple of buttons I wouldn't use. Also added the IP address of the Pi, so that when running on DHCP I can log in easily. And the file name to the top of the screen.