I was trying to make some buttons that will start/stop the MJPG stream,
$ kill -9 'pidof mjpg_streamer'
This will stop the service for a little bit then it starts up again automatically.. Anyone done this before and can post some help
thanks
Depends on how you start _mjpg_streamer_. I would guess that you have some sort of cron job or system service script checking if it have died which then automatically restarts it. You'll have to either inactivate that automation as well by your button, or revert to entirely manual control of starting and stopping the streamer server.
@bubbasnow let me guess, you are running octopi, right? Because that one runs a little script wrapper around mjpg-streamer that will restart it after 2min. Try to additionally kill "webcamDaemon".
Yes I'm running it on pi, I will try that tonight. Thanks!
On Apr 18, 2014 8:16 AM, "Gina Häußge" [email protected] wrote:
@bubbasnow https://github.com/bubbasnow let me guess, you are running
octopi, right? Because that one runs a little script wrapper around
mjpg-streamer that will restart it after 2min. Try instead killing
"webcamDaemon".—
Reply to this email directly or view it on GitHubhttps://github.com/foosel/OctoPrint/issues/441#issuecomment-40804659
.
alright, so i tested this in putty first.
i do a killall webcamDaemon mjpg_streamer
and the process stops and stays dead
and then i nohup /home/pi/scripts/webcamDaemon > foo.out 2> foo.err < /dev/null &
and the service starts again in putty
thinking this is working i create some
command: killall webcamDaemon mjpg_streamer
and this works from the system pull down menu
but
command: nohup /home/pi/scripts/webcamDaemon > foo.out 2> foo.err < /dev/null &
OctoPrint says it was completed successfully but the camera never turns back on.
I am using nohup because if i just do a regular start of webcamDaemon it will run and octoprint will just hang.
webcamDaemon & does not run this script in the background
Shot in the dark, but try putting this into quotes.
ok here is what i got
- action: WebcamOn
command: "nohup /home/pi/scripts/webcamDaemon > foo.out 2> foo.err < /dev/null &"
confirm: false
name: Start Webcam
- action: WebcamOff
command: killall webcamDaemon mjpg_streamer
confirm: false
name: Stop Webcam
still does not work
- action: WebcamOn
command: 'nohup /home/pi/scripts/webcamDaemon > foo.out 2> foo.err < /dev/null &'
confirm: false
name: Start Webcam
- action: WebcamOff
command: killall webcamDaemon mjpg_streamer
confirm: false
name: Stop Webcam
Octoprint will not start
just to try something different i made a nano test
on the first line i wrote: nohup /home/pi/scripts/webcamDaemon > foo.out 2> foo.err < /dev/null & on the first line, saved.
in the bash i did a killall webcamDaemon mjpg_streamer to shut everything down
then did a bash /home/pi/test and the webcam did indeed turn on.
so i went to config.yaml
- action: WebcamOn
command: bash /home/pi/test
confirm: false
name: Start Webcam
- action: WebcamOff
command: killall webcamDaemon mjpg_streamer
confirm: false
name: Stop Webcam
and selected the option from the system pull down and it says green successful, but the camera still did not start :(
Came across this one as I wanted to do exactly the same: start/stop the stream from Octoprint and not having it running all the time...
Fwtiw, the following works perfectly:
Very basic shell script: /usr/local/bin/raspi_streamer
(I have mjpg_streamer installed in /usr/local/bin /usr/local/lib )
#!/bin/bash
# Start / stop streamer
Daemon=mjpg_streamer
DaemonBase=/usr/local
DaemonArgs="-i \"input_raspicam.so -fps 5 -hf -vf\" -o \"output_http.so\""
case "$1" in
start)
eval LD_LIBRARY_PATH=${DaemonBase}/lib ${DaemonBase}/bin/${Daemon} ${DaemonArgs} >/dev/null 2>&1 &
echo "$0: started"
;;
stop)
pkill -x ${Daemon}
echo "$0: stopped"
;;
*)
echo "Usage: $0 {start|stop}" >&2
;;
esac
and in the Octoprint config file:
- action: streamon
command: /usr/local/bin/raspi_streamer start
confirm: false
name: Start video stream
- action: streamoff
command: /usr/local/bin/raspi_streamer stop
confirm: false
name: Stop video stream
Hi, I think this issue/question should have its status changed to "closed" as the solution provided by Amedee above works perfectly. I have tested it extensively in the last couple of weeks, with a couple of changes (I have a Logitech USB webcam attached to my Raspberry Pi).
Fine with me... :)
Amedee's solution is great except that, I assume thanks to WebcamDaemon, the solution isn't "sticky." In just a few minutes, the webcam will restart. This is potentially a home security issue, even when Octoprint is otherwise secured. Really, this is a great start, but access controls for the camera stream should be default. (Sorry for the x-post from #368)
WebcamDaemon is from OctoPi, so you should better complain there ;)
But you could do exactly the same in OctoPi, replacing the start/stop in the script by something like:
start)
/home/scripts/webcamDaemon >/dev/null 2>&1 &
echo "$0: started"
;;
stop)
pkill -x webcamDaemon
echo "$0: stopped"
;;
(I am not running OctpPi myself, so I can't test, this is just a guess looking at the sources...)
@jonathanbruder, @bubbasnow:
Here's a script that works with OctoPi. Modified from Amedee's above but using the OctoPi's convention of using the pi user for running the daemon. (I'm not sure why the scripts are in the pi user's space. The reason for the script at all is to cover the other kinds of webcams.) Don't use the eval from Amedee's script because then the calling script waits for the children to all quit which they never do because of the forever loop in the daemon. And that will make OctoPrint stop working.
I'm sure you could also just use Amedee's script and location and just swap out the start and stop lines, but I went for the OctoPi convention and didn't try it the other way. But definitely you'd need to get rid of the eval.
Put the following in /home/pi/scripts/webcam:
#!/bin/bash
# Start / stop streamer daemon
case "$1" in
start)
sudo -u pi /home/pi/scripts/webcamDaemon >/dev/null 2>&1 &
echo "$0: started"
;;
stop)
pkill -x webcamDaemon
pkill -x mjpg_streamer
echo "$0: stopped"
;;
*)
echo "Usage: $0 {start|stop}" >&2
;;
esac
Then, in the system: section of /home/pi/.octoprint/config.yaml put the following:
- 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
There is no point in 'sudoing' to pi as this script is supposed to be run from the pi deamon, so it will always be run as the pi user.
Obviously for the location of the streamer software you can put it wherever it makes you happy. My view is that it had nothing to do with OctoPrint per say and can be used separately, which is why I put it in /usrl/local. But again it does not matter at all...
Oh yeah. I grabbed that line from the OctoPi sources and assumed they'd done that on purpose because they were running from root. So no sudo would be better. And I agree with you on the location, I think I'd prefer /usr/local personally.
I've spent an entire day trying to get this to work, but it's almost like Octoprint isn't even recognizing the config.yaml file. I have no clue what I'm doing wrong. I set it up identical to Amedee's solution, minus the fact that I had to change mine to input_uvc.so -y, and I got nothing from it.
By "almost like", do you mean the menu items don't show up or they don't do anything? We should probably move this conversation to the google group since it is more like a support forum question than a github issue. If the menu items aren't showing up in the system dropdown, they're in the wrong config.yaml, they're in the wrong part of config.yaml, they aren't indented properly or perhaps you didn't restart octoprint?
They're not showing up in any menu. I've got it in the config file in the user OctoPrint folder. I restarted octoprint several times, but I may not have it indented properly. The only settings I have in the file are for the webcam, and even the port settings don't show up on the menu.
I think you might be editing the wrong file. There should be other settings in there from before you started messing around, like for shutdown and reboot, etc. You're running an OctoPi image on a R.Pi right? If so, the config file is /home/pi/.octoprint/config.yaml. I'd ask you to upload it so I can look at it but you don't want to do that since it has a couple of secrets in it. You could copy it somewhere locally, delete those lines or replace the secrets with "something something" and then upload it to gist.github.com and paste a link here. Or better yet, start a thread here: https://groups.google.com/forum/#!forum/octoprint. I'll watch for it.
Unfortunately the webcam restarts after a dozen of seconds for both provided scripts. Now, I'm using a completely different solution which works fine for me. USB shutdown requests: hub-ctrl. It takes half a minute for the cam to be recognized again.
any idea how to stop the restart ? hub-ctrl is not suitable for me, i am using the raspberry camera.
While I can't help with the above comment by @HendrikRoth, current OctoPi distributions (I think starting with 0.12, definitely the current 0.13) have a proper initscript for the webcam service, so sudo service webcamd start, sudo service webcamd stop and sudo service webcamd restart should work out of the box and be suitable for use in OctoPrint's system commands (as long as the user has the right to execute that command via sudo).
Thanks, worked fine!
Most helpful comment
While I can't help with the above comment by @HendrikRoth, current OctoPi distributions (I think starting with 0.12, definitely the current 0.13) have a proper initscript for the webcam service, so
sudo service webcamd start,sudo service webcamd stopandsudo service webcamd restartshould work out of the box and be suitable for use in OctoPrint's system commands (as long as the user has the right to execute that command via sudo).