{"id":485,"date":"2019-02-08T18:28:45","date_gmt":"2019-02-08T23:28:45","guid":{"rendered":"http:\/\/www.lazytrap.com\/trapped\/?p=485"},"modified":"2019-02-08T18:55:36","modified_gmt":"2019-02-08T23:55:36","slug":"octoprint-autostart-script","status":"publish","type":"post","link":"http:\/\/www.lazytrap.com\/trapped\/?p=485","title":{"rendered":"Octoprint Autostart Script"},"content":{"rendered":"\n<p>My goal: add a startup script to adjust my camera&#8217;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.<br><br>See this post for controlling the camera settings and determine the values you want to set in the script: <a href=\"http:\/\/www.lazytrap.com\/trapped\/?p=472\">Logitech c920 Octoprint Fine tuning <\/a><br><br>Note: I originally tried restoring the camera control settings using the uvcdynctrl &#8211;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&#8217;s value (as seen below).<\/p>\n\n\n\n<p>The steps:<br>1. SSH to your Pi running Octoprint.<br>2. Create a startup script in init.d, I named mine camera<br>3. Set the script to executable<br>4. Edit script and add uvcdynctrl commands to adjust camera<br>5. Require local filesystem, networking, and octoprint to start before executing<br>6. Add the script to startup services using update-rc.d<br>7. Reboot<br><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">pi@octopi:~ $ sudo bash<br> [sudo] password for pi:<br> root@octopi:\/home\/pi# cd \/etc\/init.d<br> root@octopi:\/etc\/init.d# touch camera<br> root@octopi:\/etc\/init.d# chmod +x camera<br> root@octopi:\/etc\/init.d# nano camera<\/pre>\n\n\n\n<p>The script with my personal settings (tweak to your own needs).<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; auto-links: false; title: ; notranslate\" title=\"\">\n#!\/bin\/sh\n\n### BEGIN INIT INFO\n# Provides:          camera\n# Required-Start:    $local_fs networking octoprint\n# Required-Stop:\n# Should-Start:\n# Should-Stop:\n# Default-Start:     2 3 4 5\n# Default-Stop:      0 1 6\n# Short-Description: Camera Settings\n# Description:       Sets UVC control settings for camera on boot\n### END INIT INFO\n\nuvcdynctrl -s &#039;Focus, Auto&#039; 0\nuvcdynctrl -s &#039;Sharpness&#039; 200\nuvcdynctrl -s &#039;White Balance Temperature&#039; 2500\nuvcdynctrl -s &#039;White Balance Temperature, Auto&#039; 0\nuvcdynctrl -s &#039;White Balance Temperature&#039; 2500\nuvcdynctrl -s &#039;Contrast&#039; 128\nuvcdynctrl -s &#039;Brightness&#039; 138\nuvcdynctrl -s &#039;Focus (absolute)&#039; 29\n\nexit 0\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"733\" height=\"722\" src=\"http:\/\/www.lazytrap.com\/trapped\/wp-content\/uploads\/2019\/02\/image.png\" alt=\"\" class=\"wp-image-486\" srcset=\"http:\/\/www.lazytrap.com\/trapped\/wp-content\/uploads\/2019\/02\/image.png 733w, http:\/\/www.lazytrap.com\/trapped\/wp-content\/uploads\/2019\/02\/image-300x295.png 300w, http:\/\/www.lazytrap.com\/trapped\/wp-content\/uploads\/2019\/02\/image-660x650.png 660w\" sizes=\"(max-width: 733px) 100vw, 733px\" \/><\/figure>\n\n\n\n<p>Finally, run update-rc.d to add the script to startup.<br><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root@octopi:\/etc\/init.d# update-rc.d camera defaults<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">root@octopi:\/etc\/init.d# reboot<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>My goal: add a startup script to adjust my camera&#8217;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\u2026 <span class=\"read-more\"><a href=\"http:\/\/www.lazytrap.com\/trapped\/?p=485\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":470,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[149],"tags":[161,155,157,160,152,159,162,158,154],"jetpack_featured_media_url":"http:\/\/www.lazytrap.com\/trapped\/wp-content\/uploads\/2019\/02\/print.jpg","_links":{"self":[{"href":"http:\/\/www.lazytrap.com\/trapped\/index.php?rest_route=\/wp\/v2\/posts\/485"}],"collection":[{"href":"http:\/\/www.lazytrap.com\/trapped\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.lazytrap.com\/trapped\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.lazytrap.com\/trapped\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.lazytrap.com\/trapped\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=485"}],"version-history":[{"count":7,"href":"http:\/\/www.lazytrap.com\/trapped\/index.php?rest_route=\/wp\/v2\/posts\/485\/revisions"}],"predecessor-version":[{"id":503,"href":"http:\/\/www.lazytrap.com\/trapped\/index.php?rest_route=\/wp\/v2\/posts\/485\/revisions\/503"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.lazytrap.com\/trapped\/index.php?rest_route=\/wp\/v2\/media\/470"}],"wp:attachment":[{"href":"http:\/\/www.lazytrap.com\/trapped\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.lazytrap.com\/trapped\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=485"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.lazytrap.com\/trapped\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}