{"id":195,"date":"2020-04-11T11:17:05","date_gmt":"2020-04-11T04:17:05","guid":{"rendered":"https:\/\/prosindo.com\/blog\/?p=195"},"modified":"2020-04-11T11:17:39","modified_gmt":"2020-04-11T04:17:39","slug":"octroprint-turn-off-webcam-automatically","status":"publish","type":"post","link":"https:\/\/prosindo.com\/blog\/2020\/04\/11\/octroprint-turn-off-webcam-automatically\/","title":{"rendered":"Octroprint: Turn off webcam automatically"},"content":{"rendered":"<p>Seen a post about webcam at jcode, i made my own version because:<br \/>\n1. need no additional python libraries<br \/>\n2. need camera stay on while printer is on, ready for next print, not depending on octoprint status<\/p>\n<p>Running cron script every minute:<\/p>\n<p><code>*\t*\t*\t*\t*\t\/home\/pi\/autocam.py<\/code><\/p>\n<p>and script autocam.py:<\/p>\n<pre>#!\/usr\/bin\/python\r\n\r\nimport os\r\nimport subprocess\r\n\r\nSERIAL_DEV = \"\/dev\/serial\/by-id\/your-serial-port-id\"\r\n\r\ndef checkserial():\r\n  return os.path.exists(SERIAL_DEV)\r\n\r\ndef checkwebcam():\r\n  r = subprocess.check_output(\"ps ax | grep mjpg_streamer -c\",shell=True)\r\n  c = int(r)-2\r\n  return c &gt; 0\r\n\r\nif __name__ == \"__main__\":\r\n  if checkserial() and not checkwebcam():\r\n    os.system(\"echo $(date '+%Y-%m-%d %H:%M:%S') start &gt;&gt; autocam.log\")\r\n    os.system(\"service webcamd start\")\r\n  elif not checkserial() and checkwebcam():\r\n    os.system(\"echo $(date '+%Y-%m-%d %H:%M:%S') stop &gt;&gt; autocam.log\")\r\n    os.system(\"service webcamd stop\")\r\n<\/pre>\n<p>Source: https:\/\/jcode.me\/octoprint-turning-off-webcam-automatically\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Seen a post about webcam at jcode, i made my own version because: 1. need no additional python libraries 2. need camera stay on while printer is on, ready for next print, not depending on octoprint status Running cron script every minute: * * * * * \/home\/pi\/autocam.py and script autocam.py: #!\/usr\/bin\/python import os import &hellip; <a href=\"https:\/\/prosindo.com\/blog\/2020\/04\/11\/octroprint-turn-off-webcam-automatically\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Octroprint: Turn off webcam automatically&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-195","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/posts\/195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/comments?post=195"}],"version-history":[{"count":4,"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/posts\/195\/revisions"}],"predecessor-version":[{"id":199,"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/posts\/195\/revisions\/199"}],"wp:attachment":[{"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/media?parent=195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/categories?post=195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/tags?post=195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}