I have three USB webcams attached to my RPi 4. I've followed the instructions on Setting up multiple webcams in OctoPi the right way to set them up.
After a reboot, everything works great. I have the multicam plugin and I can see all three cameras. However, after about 10 minutes or so, none of my cameras work. When I try to open the stream, it just hangs.
mjpg_streamer is still running:
$ ps aux | grep mj
root 505 0.0 0.5 34720 5168 ? Sl 15:41 0:03 ./mjpg_streamer -o output_http.so -w ./www-octopi -n -p 8080 -i input_uvc.so -r 1280x720 -f 30 -d /dev/video0
root 545 0.0 0.9 29500 9196 ? Sl 15:41 0:02 ./mjpg_streamer -o output_http.so -w ./www-octopi -n -p 8081 -i input_uvc.so -r 1280x720 -f 10 -d /dev/video4
root 564 0.1 0.4 24700 4336 ? Sl 15:41 0:04 ./mjpg_streamer -o output_http.so -w ./www-octopi -n -p 8082 -i input_uvc.so -r 640x480 -d /dev/video2
Anyone have a clue what could be the problem? I used to have a bunch of hacked up files to support multiple cameras, based on how older versions of OctoPi worked. These problems started happening after I switched to the "proper" method for OctoPi 0.18. It's possible that I might have some vestige of the old method lying around.
OctoPrint version : 1.7.2
OctoPi version : 0.18.0
webcamd.log (8.1 KB)
dmesg.log (27.5 KB)
syslog.log (102.8 KB)
It looks like it's below the webcam streaming software - the dmesg log tells most of the story here:
[ 825.253366] usb usb1-port1: disabled by hub (EMI?), re-enabling...
[ 825.253401] usb 1-1: USB disconnect, device number 2
[ 825.253423] usb 1-1.1: USB disconnect, device number 3
[ 825.253443] usb 1-1.1.1: USB disconnect, device number 8
[ 825.253881] lan78xx 1-1.1.1:1.0 eth0: Failed to read register index 0x00000120. ret = -19
[ 825.253922] lan78xx 1-1.1.1:1.0 eth0: Failed to read register index 0x00000120. ret = -19
[ 825.253951] lan78xx 1-1.1.1:1.0 eth0: Failed to read register index 0x00000120. ret = -19
[ 825.253981] lan78xx 1-1.1.1:1.0 eth0: Failed to read register index 0x00000098. ret = -19
[ 825.254002] lan78xx 1-1.1.1:1.0 eth0: Failed to write register index 0x00000098. ret = -19
[ 825.254140] lan78xx 1-1.1.1:1.0 eth0: Failed to read register index 0x00000098. ret = -19
[ 825.254161] lan78xx 1-1.1.1:1.0 eth0: Failed to write register index 0x00000098. ret = -19
[ 825.255142] lan78xx 1-1.1.1:1.0 eth0 (unregistering): Failed to read register index 0x00000024. ret = -19
[ 825.305745] usb 1-1.1.2: USB disconnect, device number 5
[ 825.447492] usb 1-1.1.3: USB disconnect, device number 7
[ 825.451409] usb 1-1.2: USB disconnect, device number 6
[ 825.534611] usb 1-1.3: USB disconnect, device number 4
It looks like the USB hub resets itself. The log itself is questioning EMI, but that's not necessarily the issue. Maybe with 3 webcams the USB controller is getting too warm and resetting? Not completely obvious but at least we can see a problem in the logs.
If you run with just one webcam connected, does it last for longer? Or still quitting after 13 minutes as this one is doing.
If I do "service webcamd restart", the problem appears to fix itself until the next reboot.
When I disconnect once of the cameras, it seems to work.
I then tried connecting all the cameras to a powered USB hub, but that just made things worse. After a few minutes, all of the cameras stopped working.
[ 51.554240] usb 1-220.127.116.11: reset high-speed USB device number 6 using dwc_otg
[ 56.834211] usb 1-18.104.22.168: device descriptor read/64, error -110
[ 72.274225] usb 1-22.214.171.124: device descriptor read/64, error -110
Anyway, it's obviously a USB power problem. I'll try a few different things. Maybe the hub is broken.
What's the best way to have OctoPi run "sudo service webcamd restart" a few minutes after OctoPrint starts?
You can have that with a systemd timer and onBootSec=6min or so, plus a cooresponding .service which has a bash script in exec which in turn does the restart
But there is an alternative, add an entry to restart webcamd to OctoPrint's system menu.
For this you need to edit config.yaml and add:
- action: restartwebcam
command: sudo systemctl restart webcamd
confirm: You are about to restart the webcam
name: Restart Webcam
and here are the scripts for a systemd timer to restart the webcamd.service 6 minutes after boot - it was easier to post them from the other computer.
It takes three tiny files, #1 is a bash script that does the work.
The example creates and edits the files with nano
sudo nano /usr/local/bin/restart_webcamd.sh
sudo systemctl restart webcamd
Ctrl X and Y to save the file, then make it executable:
chmod 755 /usr/local/bin/restart_webcamd.sh
File #2 is the service file which defines what to do,
sudo nano /etc/systemd/system/restart_webcam.service
and finally the timer definition,
sudo nano /etc/systemd/system/restart_webcam.timer
Description=timer for restartwebcam
You activate this by enabling the timer:
sudo systemctl enable restart_webcam.timer
As long as foo.timer corresponds to foo.service systemd will connect the two scripts.