QIDITECH / QIDI_Q1_Pro

GNU Affero General Public License v3.0
57 stars 8 forks source link

Possible fix for webcam disappearing after a while #104

Open rigor789 opened 1 week ago

rigor789 commented 1 week ago

A few people in #86 and on Discord, including myself experienced an issue where the webcam disappears after a while, and doesn't come back until a power cycle - after which it disappears shortly after anyways.

Doing some digging, seems like the camera gets disconnected/reconnected, and this causes it to stop showing up. Could be down to a power supply issue I suppose, as the connections are not loose in any way.

I was able to work around the issue on my machine by adding an udev rule, here are the exact steps I took:

  1. ssh into the printer as root ssh root@<printer-ip> password is makerbase
  2. nano /etc/udev/rules.d/99-webcam-reconnect.rules and add this:
    SUBSYSTEM=="usb", ATTR{idVendor}=="1bcf", ATTR{idProduct}=="0b09", ACTION=="add", RUN+="/root/restart-webcamd.sh"
  3. nano /root/restart-webcamd.sh and add this:
    #!/bin/bash
    # Restart the webcamd service
    sudo systemctl restart webcamd
    echo "Restarted webcamd: $(date)" >> /root/restart-webcamd.log
  4. chmod +x /root/restart-webcamd.sh

This should run restart-webcamd.sh whenever the webcam is (re)connected.

Double check the idVendor/idProduct in case yours is different (likely not), you can verify with dmesg -w and search for HD Camera, mine says something like this:

[  188.383834] usb 2-1.4: Found UVC 1.00 device HD Camera (1bcf:0b09)
[  188.404976] input: HD Camera: HD Camera as /devices/platform/ff5c0000.usb/usb2/2-1/2-1.4/2-1.4:1.0/input/input1
[  188.405785] usbcore: registered new interface driver uvcvideo

You see the vendor/product id in the parenthesis (1bcf:0b09).

With this in place, my webcam no longer disappears, and I can confirm the script runs by inspecting the /root/restart-webcamd.log I added:

Restarted webcamd: Tue Nov 12 12:07:52 CET 2024
Restarted webcamd: Tue Nov 12 16:51:58 CET 2024
Restarted webcamd: Tue Nov 12 16:54:34 CET 2024
Restarted webcamd: Tue Nov 12 17:09:11 CET 2024
Restarted webcamd: Tue Nov 12 17:36:51 CET 2024

Hope this helps someone in a similar boat (benchy?!).