Octoprint Autostart Script

By | February 8, 2019

My goal: add a startup script to adjust my camera’s settings on reboot. I own Logitech c920 and I use it to monitor my prints on a Ender 3 pro. The c920 has several controls that can be adjusted and the primary one I wanted to change was to turn off Auto Focus.

See this post for controlling the camera settings and determine the values you want to set in the script: Logitech c920 Octoprint Fine tuning

Note: I originally tried restoring the camera control settings using the uvcdynctrl –load=file command, but something about loading the settings this way upon reboot fails to work completely. I found it more reliable to set each control’s value (as seen below).

The steps:
1. SSH to your Pi running Octoprint.
2. Create a startup script in init.d, I named mine camera
3. Set the script to executable
4. Edit script and add uvcdynctrl commands to adjust camera
5. Require local filesystem, networking, and octoprint to start before executing
6. Add the script to startup services using update-rc.d
7. Reboot

pi@octopi:~ $ sudo bash
[sudo] password for pi:
root@octopi:/home/pi# cd /etc/init.d
root@octopi:/etc/init.d# touch camera
root@octopi:/etc/init.d# chmod +x camera
root@octopi:/etc/init.d# nano camera

The script with my personal settings (tweak to your own needs).

#!/bin/sh

### BEGIN INIT INFO
# Provides:          camera
# Required-Start:    $local_fs networking octoprint
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Camera Settings
# Description:       Sets UVC control settings for camera on boot
### END INIT INFO

uvcdynctrl -s 'Focus, Auto' 0
uvcdynctrl -s 'Sharpness' 200
uvcdynctrl -s 'White Balance Temperature' 2500
uvcdynctrl -s 'White Balance Temperature, Auto' 0
uvcdynctrl -s 'White Balance Temperature' 2500
uvcdynctrl -s 'Contrast' 128
uvcdynctrl -s 'Brightness' 138
uvcdynctrl -s 'Focus (absolute)' 29

exit 0

Finally, run update-rc.d to add the script to startup.

root@octopi:/etc/init.d# update-rc.d camera defaults
root@octopi:/etc/init.d# reboot

Leave a Reply

Your email address will not be published. Required fields are marked *