Setting up multiple webcams in OctoPi the right way

If you can, check the temperatures of the USB chip on the board, on the Pi 4 particularly I have seen people put heatsinks on as they can overheat and it is possible it is cutting some of the load - I'm not entirely sure if that is the case or how that works, but maybe something to keep in mind. Some brief details on the raspberry pi documentation, the dmesg command would definitely be useful - it may provide you with errors when the cameras go down.

ok will have to take out pi4 and see if the chips are hot. And will check the logs... Thanks again

After tinkering around a bit.. no heat issue on the usb chip, but I was able to get all 3 "usb" cameras working if I disabled my raspicam. And those have been constantly streaming for about 2 days. So the raspicam is taking resources away but not sure where. I'm going to try a 4th USB camera and see how that goes. Now to find a usb camera no one will notice not being there.. hahahaha

you could try forcing your raspicam to run in usb mode by setting camera="usb" and it will still work.

I tried your suggestion but its only going back and forth of my usb cameras. Since i'm not defining a device id.. think its going from /dev/video1 or video2 or some video device but not the raspicam. In the webcamd.log shows a lot of invalid V4L2_set_control errors. so unless there is another way to specifically call the raspicam not sure if this is going to work. But please correct me.. ok gonna back to the camera hunt..

Serving multiple webcam streams with https://

I had followed Let's Encrypt on OctoPi to serve it all on https:// now how to get the additional usbCam into the scheme?

I did it thus, adding two bits to /etc/haproxy/haproxy.cfg

frontend usbcam
        bind :::8082
        bind :::8443 v4v6 ssl crt /etc/ssl/private/intern/octopi.intern-combined.pem
        use_backend usbcam


backend usbcam
        server usbcam1  127.0.0.1:8081
        errorfile 503 /etc/haproxy/errors/503-no-webcam.http

This isn't usually required, I'm not entirely sure why you have an additional frontend block outside the standard frontend public one. Editing the haproxy setup as above in the guide works for me, and uses https for every webcam I add.

thanks to this guide I was able to get both of my cameras working but every time the PI needs a reboot, refresh of octoprint or I power it down for any amount of time, I have to send ssh to restart webcamd. Does anyone have any ideas of a work around or a fix?

what does it return when you ssh into the pi and type:
systemctl status webcamd

octopi:~$ systemctl status webcamd

e[?1he=
● webcamd.service - the OctoPi webcam daemon with the user specified confige[m
   Loaded: loaded (/etc/systemd/system/webcamd.service; enabled; vendor preset: e[m
   Active: inactive (dead) since Fri 2021-07-30 06:20:00 EDT; 2h 0min agoe[m
  Process: 709 ExecStart=/root/bin/webcamd (code=exited, status=0/SUCCESS)e[m
e[m
Jul 30 06:19:51 octopi mjpg_streamer[755]: MJPG-streamer [755]: www-folder-path.e[m
Jul 30 06:19:51 octopi mjpg_streamer[755]: MJPG-streamer [755]: HTTP TCP port...e[m
Jul 30 06:19:51 octopi mjpg_streamer[755]: MJPG-streamer [755]: HTTP Listen Addre[m
Jul 30 06:19:51 octopi mjpg_streamer[755]: MJPG-streamer [755]: username:passwore[m
Jul 30 06:19:51 octopi mjpg_streamer[755]: MJPG-streamer [755]: commands........e[m
Jul 30 06:19:51 octopi mjpg_streamer[755]: MJPG-streamer [755]: starting input pe[m
Jul 30 06:19:51 octopi mjpg_streamer[755]: MJPG-streamer [755]: starting output e[m
Jul 30 06:19:51 octopi mjpg_streamer[755]: MJPG-streamer [755]: Starting Camerae[m
Jul 30 06:20:00 octopi systemd[1]: webcamd.service: Succeeded.e[m
Jul 30 06:20:00 octopi systemd[1]: Stopped the OctoPi webcam daemon with the usee[m
e[7mlines 1-15/15 (END)e[me[K

Do you have The Spaghetti Detective plugin installed? If it's premium webcam option is enabled it will stop the webcamd service like that.

1 Like

Turning off premium, seems to have fixed it. THANK YOU!

I've added a note to the guide about TSD premium, since there's been a few people confused by this.

I'm trying to configure a raspi cam and a USB cam. If I do nothing other than edit the default octopi.txt to camera="raspi" my setup starts failing. If I edit the default to camera="usb" the raspi cam works?? Is there some kind of way that my raspberry PI cam became a USB device?

Also I should mention that ls /dev/v4l/by-id/ does not exist. I have "by-path".

A raspicam can be accessed as either, the system does represent it as a USB camera so that it's compatible with applications that work with USB cameras.

Using it as a USB camera means that you lose the specific raspicam options, however since you are then limited to the USB camera options. It does, however, mean that you can use USB camera things, like the Camera Settings plugin.

Any idea why I can't address it as a raspberry pi camera?

I'm having trouble with getting my cheap unbranded usb webcam to work. I put this in:

camera_usb_options="-r 640x480 -f 10 -d usb-Ruision_UVC_Camera_20200416-video-index0"

but I'm seeing in the webcamd.log:

config file='/boot/octopi.conf.d/webcam2.txt':USB device was not set in options, start MJPG-streamer with the first found video device: /dev/video0

and

Running ./mjpg_streamer -o output_http.so -w ./www-octopi -n -p 8081 -i input_uvc.so -r 640x480 -f 10 -d usb-Ruision_UVC_Camera_20200416-video-index0 -d /dev/video0

note that it's showing the -d that I put in, but also a -d /dev/video0 (which is my raspi cam, when it's installed). This results in both 8080 and 8081 showing the raspi cam. If the raspi isn't plugged in, it doesn't find anything and the web stream won't connect.

Any ideas? I'm on Octopi 0.18 on a 4gb Pi 4B

NEVERMIND... didn't have the /dev/v41/by-id/ in the device path.

you have to include this in front of the id...

camera_usb_options="-r 640x480 -f 10 -d /dev/v4l/by-id/usb-Ruision_UVC_Camera_20200416-video-index0"

OK, a bunch of water under the bridge... had my USB camera unplugged for a while during installing a new board in my Ender3. Now, it doesn't work, where it did (at least for a short time) after I had the above issue. Now there's nothing on :8081, and seeing something similar to the above in the webcamd log (with the v41 path included). However, when I go to see if the webcam's ID is the same, I can't view the v41 folder. It tells me

pi@octopi:~ $ ls /dev/v41/by-id
ls: cannot access '/dev/v41/by-id': No such file or directory
pi@octopi:~ $ ls /dev/v41
ls: cannot access '/dev/v41': No such file or directory

I look at /dev, and I can see a v41 that's colored the same as all the other folders. If I do "ls /dev/v* -l" I get a lot of v* files, along with:

crw-rw---- 1 root video  81,   9 Sep  8 17:12 /dev/video2

/dev/v4l:
total 0
drwxr-xr-x 2 root root  80 Sep  8 17:12 by-id
drwxr-xr-x 2 root root 180 Sep  8 17:12 by-path

So there's something, there, but I can't figure out how to look at it.

I'm at the limits of my linux admin knowledge. Any suggestions?

p.s. not that it matters, because it doesn't seem to look at the folder yet (just tells me I didn't set it in options), webcam2.txt has

camera_usb_options="-r 1024x768 -f 10 -d /dev/v41/by-id/usb-Ruision_UVC_Camera_20200416-video-index0"

and the log has

config file='/home/pi/klipper_config/webcam2.txt':USB device was not set in options, start MJPG-streamer with the first found video device: /dev/video0
<13>Sep  8 17:25:14 pi: Starting USB webcam
Checking for VL805 (Raspberry Pi 4)...
  - It seems that you don't have VL805 (Raspberry Pi 4).
    There should be no problems with USB (a.k.a. select() timeout)
Running ./mjpg_streamer -o output_http.so -w ./www-mjpgstreamer -n -p 8081 -i input_uvc.so -r 1024x768 -f 10 -d /dev/v41/by-id/usb-Ruision_UVC_Camera_20200416-video-index0 -d /dev/video0

There's a typo in your /dev/v4l path. It a lowercase L, not a 1. Then you'll be able to find the correct device.

2 Likes