Skip to content

How to Start on Boot

Claude Pageau edited this page Mar 18, 2024 · 15 revisions

Start speed-cam.py and webserver.py on Boot and Automate makehtml.py

Introduction

speed-cam.sh is a bash script that runs speed-cam.py as a background task after a short wait period. If the script is run a second time it will display the pid of the background task. speed-cam.sh can be edited using nano to send verbose logging to a log file when running as a background task. See code comments for changing the default behavior. Default is no redirection of verbose logging. There is a 10 second wait in the script to allow time for RPI startup services to complete before starting speed-cam.py This can be increased if there is a problem.
IMPORTANT: Change the config.py variable verbose=False to suppress console messages, otherwise messages will be sent to the foreground console session and may cause problems.

Ownership of Files and Folders

Make sure the files in rpi-speed-camera folder are all owned by pi before running process in background as user pi. To change ownership execute the following command

sudo chown -R pi:pi /home/pi/speed-camera/*
ls -Rl /home/pi/speed-camera | more

How To Start on Boot

  • Option 1 run.sh For details see How-to-use-run.sh

  • Option 2 rc.local To auto launch speed-cam.py and/or webserver.py on boot-up of raspberry pi, perform the following

    sudo nano /etc/rc.local

In nano add the following command to the rc.local file just before the exit 0 command. This will launch speed-cam.py and the webserver.py in the background running under the pi user (not root). Note the webserver startup is optional.

su pi -c "/home/pi/speed-camera/speed-cam.sh start > /dev/null"
su pi -c "/home/pi/speed-camera/webserver.sh start > /dev/null"

ctrl-x y to save and exit nano editor

Reboot RPI and test operation by triggering motion and checking images are successfully saved to your images folder (link to html/images).

sudo reboot

Login and check if speed-cam.sh and or webserver is running or verify they are running under pi user

ps -ef | grep python | grep -v grep
or
pgrep -fa speed
pgrep -fa web

To stop the speed-cam and or webserver background task.

cd ~/speed-camera
./speed-cam.sh stop 
./webserver.sh stop

You can also do this using menubox.sh

How to Automate makehtml.py

If you are running speed-cam.py and webserver.py as background tasks on boot, you may wish to automate creation of web pages by adding makehtml.py to a crontab entry per the following

crontab -e

Add the following example entry to run makehtml.py every fifteen (15) minutes

*/15 * * * * /home/pi/speed-camera/makehtml.py > /dev/null

Verify that the crontab entry is working. You can also temporarily redirect output to a file instead of null

*/15 * * * * /home/pi/speed-camera/makehtml.py > /home/pi/rpi-speed-camera/makehtml.log

Github Repo