0

I have 2 identical webcams plugged into my Raspberry Pi. I want discern which camera is which based on the USB port they are plugged in to.

This is the purpose of udev, so I wrote the following rule:

SUBSYSTEM=="usb", KERNEL=="1-1.3", ATTR{idVendor}=="05a3", ATTR{idProduct}=="9422", SYMLINK+="klastle/vlvid"
SUBSYSTEM=="usb", KERNEL=="1-1.5", ATTR{idVendor}=="05a3", ATTR{idProduct}=="9422", SYMLINK+="klastle/irvid"

Which on a reboot shows these devices:

root@raspberrypi:~# ls -rlt /dev/klastle/
total 0
lrwxrwxrwx 1 root root 18 Feb 18 01:24 irvid -> ../bus/usb/001/007
lrwxrwxrwx 1 root root 18 Feb 18 01:24 vlvid -> ../bus/usb/001/005

The problem is that these are not video for linux ( V4L2 ) devices and my application cannot open them.

How can I write my rule correctly to symlink the actual /dev/video0 and /dev/video1 to /dev/klastle/irvid and /dev/klastle/vlvid?

Thanks.

UPDATE: Here is the udevadm query output for both devices:

root@raspberrypi:~# udevadm info --query=all --name=/dev/video3
P: /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5:1.0/video4linux/video3
N: video3
S: v4l/by-id/usb-Sonix_Technology_Co.__Ltd._USB_2.0_Camera_SN0001-video-index1
S: v4l/by-path/platform-3f980000.usb-usb-0:1.5:1.0-video-index1
E: DEVLINKS=/dev/v4l/by-path/platform-3f980000.usb-usb-0:1.5:1.0-video-index1 /dev/v4l/by-id/usb-Sonix_Technology_Co.__Ltd._USB_2.0_Camera_SN0001-video-index1
E: DEVNAME=/dev/video3
E: DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5:1.0/video4linux/video3
E: ID_BUS=usb
E: ID_FOR_SEAT=video4linux-platform-3f980000_usb-usb-0_1_5_1_0
E: ID_MODEL=USB_2.0_Camera
E: ID_MODEL_ENC=USB\x202.0\x20Camera
E: ID_MODEL_ID=9422
E: ID_PATH=platform-3f980000.usb-usb-0:1.5:1.0
E: ID_PATH_TAG=platform-3f980000_usb-usb-0_1_5_1_0
E: ID_REVISION=0100
E: ID_SERIAL=Sonix_Technology_Co.__Ltd._USB_2.0_Camera_SN0001
E: ID_SERIAL_SHORT=SN0001
E: ID_TYPE=video
E: ID_USB_DRIVER=uvcvideo
E: ID_USB_INTERFACES=:0e0100:0e0200:010100:010200:
E: ID_USB_INTERFACE_NUM=00
E: ID_V4L_CAPABILITIES=:capture:
E: ID_V4L_PRODUCT=USB 2.0 Camera: H264 USB Camera
E: ID_V4L_VERSION=2
E: ID_VENDOR=Sonix_Technology_Co.__Ltd.
E: ID_VENDOR_ENC=Sonix\x20Technology\x20Co.\x2c\x20Ltd.
E: ID_VENDOR_ID=05a3
E: MAJOR=81
E: MINOR=3
E: SUBSYSTEM=video4linux
E: TAGS=:uaccess:seat:
E: USEC_INITIALIZED=3298533

root@raspberrypi:~# udevadm info --query=all --name=/dev/video0
P: /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/video4linux/video0
N: video0
S: v4l/by-id/usb-Sonix_Technology_Co.__Ltd._USB_2.0_Camera_SN0001-video-index0
S: v4l/by-path/platform-3f980000.usb-usb-0:1.3:1.0-video-index0
E: DEVLINKS=/dev/v4l/by-path/platform-3f980000.usb-usb-0:1.3:1.0-video-index0 /dev/v4l/by-id/usb-Sonix_Technology_Co.__Ltd._USB_2.0_Camera_SN0001-video-index0
E: DEVNAME=/dev/video0
E: DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/video4linux/video0
E: ID_BUS=usb
E: ID_FOR_SEAT=video4linux-platform-3f980000_usb-usb-0_1_3_1_0
E: ID_MODEL=USB_2.0_Camera
E: ID_MODEL_ENC=USB\x202.0\x20Camera
E: ID_MODEL_ID=9422
E: ID_PATH=platform-3f980000.usb-usb-0:1.3:1.0
E: ID_PATH_TAG=platform-3f980000_usb-usb-0_1_3_1_0
E: ID_REVISION=0100
E: ID_SERIAL=Sonix_Technology_Co.__Ltd._USB_2.0_Camera_SN0001
E: ID_SERIAL_SHORT=SN0001
E: ID_TYPE=video
E: ID_USB_DRIVER=uvcvideo
E: ID_USB_INTERFACES=:0e0100:0e0200:010100:010200:
E: ID_USB_INTERFACE_NUM=00
E: ID_V4L_CAPABILITIES=:capture:
E: ID_V4L_PRODUCT=USB 2.0 Camera: H264 USB Camera
E: ID_V4L_VERSION=2
E: ID_VENDOR=Sonix_Technology_Co.__Ltd.
E: ID_VENDOR_ENC=Sonix\x20Technology\x20Co.\x2c\x20Ltd.
E: ID_VENDOR_ID=05a3
E: MAJOR=81
E: MINOR=0
E: SUBSYSTEM=video4linux
E: TAGS=:seat:uaccess:
E: USEC_INITIALIZED=3289947
1

Your rules are matching at the wrong level in the device tree: SUBSYSTEM=="usb" says you want a symlink to something that represents the complete USB device, and not the video4linux layer. So you need SUBSYSTEM=video4linux. You also need ATTRS and KERNELS (with extra S) instead of ATTR and KERNEL, because you want to much those further up in the tree. See man udev for details.

The way to get this information is to get udevadm to spit out the whole path up to the root of tree with attributes etc., with something like

udevadm info -a -p  $(udevadm info -q path -n /dev/video3)

(you already did the inner part for the edit of your question).

So the rule should become something like

SUBSYSTEM=="video4linux", KERNELS=="1-1.3", ATTRS{idVendor}=="05a3", ATTRS{idProduct}=="9422", SYMLINK+="klastle/vlvid"

or similar, possibly depending on what you see in the device path.

-1

I had a similar problem. 4 identical cameras without serial numbers. On reboot there was a random reallocation. I needed to caption the pics, so this did not work.

The solution involves udev rules and some python code. You address the cameras as mycam1..4 instead of video0..3. So mycam1 is always the same camera regardless of what videox number it has been allocated on boot.

https://unix.stackexchange.com/a/533464/202850

  • "Too long to post here." How to make people on the internet hate you 101. I'm also unsure why you'd need python code; since - as the other answer also demonstrates - a single udev rule per device should be enough. – Stefan Fabian Jun 30 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.