Showing posts with label pi. Show all posts
Showing posts with label pi. Show all posts

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

Add the following to the script:

#!/bin/bash
# find the router gateway to ping
IP=$(/sbin/ip route | awk '/default/ { print $3 }')
#echo $IP
#interface to check
iface='wlan0'
#echo "Starting ping test on $iface"
#date
#ping -c4 -I $iface 192.168.0.1 > /dev/null
ping -c4 -I $iface $IP > /dev/null
if [ $? != 0 ]
then
  date
  echo "Ping test on $iface to $IP FAILED!  Resetting $iface"
  sudo ifdown $iface
  sudo ifup $iface
  echo "Done"
  echo
fi
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/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.

Friday, 20 May 2016

TAZ 5 with OcotPrint running on Raspberry Pi

I've had a Rev B Pi sat around on my desk for at least 5 years now, and have been trying to find a use for it. So my latest desire is to have it setup on the Taz to run OctoPrint utilizing the webcam for remote viewing of the print progress. This post is here simply for my own reference so that I can repeat various steps to get the Pi up and running again should I need to.

There is an SD image already created based on Raspbian called octopi. This is probably the simplest way to get started, however, I already had Raspbian installed and would rather do things manually, so I started by following these steps here:


Setup on a Raspberry Pi running Raspbian


I configured as per the instructions, I do remember running into a missing library at some point, but can't think what it was, something to do with python-dev?? anyway, a google search turned up the answer. I did the following:

  1. Install OctoPrint
  2. Add mjpg_streamer for webcam
  3. Configure to start on boot as server
  4. Add system commands to ocotprint interface
  5. Make everything accessable on port 80

Some important file locations:

Webcam configuration:

~/scripts/webcamDaemon
I modified the webcam resolution and frame rate as I found it was swamping the wifi link on the Pi, and would often kill the network interface. My configuration looks like this:

camera_raspi_options="-fps 4 -x 640 -y 480 -q 20 -sh 100"

Edit using: nano ~/scripts/webcamDaemon

The hidden Ocotprint configuration file:
~.octoprint/config.yaml

Edit this file using
nano ~.octoprint/config.yaml
haproxy config files:
/etc/haproxy/haproxy.cfg
/etc/default/haproxy


Currently my file has some modifications to add actions to the OctoPrint interface so that I can start and stop the webcam stream, and reboot the system. Also this file contains webcam configuration, which can be accessed and changed via the OctoPrint interface. However, for changes to take effect OctoPrint has to be re-started and the browser will need refreshing. Additions to my config file are as follows:

  system:  
  actions:  
  - action: streamon  
   command: /home/pi/scripts/webcam start  
   confirm: false  
   name: Start Video Stream  
  - action: streamoff  
   command: /home/pi/scripts/webcam stop  
   confirm: false  
   name: Stop Video Stream  
  - action: reboot  
   command: sudo reboot  
   confirm: You are about to reboot the system  
   name: Reboot  
 temperature:  
  profiles:  
  - bed: '110'  
   extruder: '245'  
   name: ABS  
  - bed: 60  
   extruder: 180  
   name: PLA  
 webcam:  
  ffmpeg: /usr/bin/avconv  
  flipH: true  
  flipV: true  
  snapshot: http://127.0.0.1:8080/?action=snapshot  
  stream: http://mywebaddress.no-ip.org:8080/?action=stream  
  watermark: false  


Usefull stuff:

To start/stop services:

sudo service octoprint {start|stop|restart}
sudo service haproxy {start|stop|restart}
~/scripts/webcam {start|stop}


So what next. I setup a no-ip account so that I could have a web address I could access from anywhere that would re-direct to my OctoPi. To do this I installed the noip service on the Pi, which updates the dynamic IP address to my no-ip hostname, instructions here:

Install no-ip DUC on Raspberry Pi

Or this one, which has the auto start instructions:

No-Ip with auto start on boot

I changed the default hostname of raspberrypi to somehting else using this guide:

Change hostname

As yet I have not got an easy way to find the OctoPi on the network without knowing it's IP address. working on this...