fluidd-core / FluiddPI

FluiddPi - A Pi image with Klipper, Moonraker, Fluidd and Web Camera support pre-installed.
https://docs.fluidd.xyz
GNU General Public License v3.0
299 stars 58 forks source link

Had to enable legacy raspicam camera stack in order for PiCamera to work #36

Open StarWhiz opened 2 years ago

StarWhiz commented 2 years ago

This is what I did to get my PiCam working in fluiddPi.

  1. raspi-config
  2. choose "3 Interface Options"
  3. choose "I1 Legacy Camera"
  4. Enable
  5. Finish raspi-config and reboot

Now PiCamera should work. Hopefully this work around will help anyone else having trouble.

Before I did the above I kept getting 502 bad gateway errors and no matter what I did in FluidUI camera settings or webcam.txt nothing would work.

Information about the legacy Raspicam stack can be found here: https://www.raspberrypi.com/documentation/accessories/camera.html

Avedena commented 2 years ago

Hi @StarWhiz , I also try to activate the Pi Cam inside Fluidd, but don't get it running. My FluiddPi is running on a Raspberry Pi 4 4GB with the Pi Camera Module 2.1 running with a Sony IMX219 sensor.

/var/log/webcam.txt:

Starting up webcamDaemon...

--- Configuration: ----------------------------
cfg_file:      /home/pi/klipper_config/webcam.txt
camera:        raspi
usb options:   -r 640x480 -f 10
raspi options: --width 1280 --height 720 --framerate 60 -quality 100
http options:  -w ./www-mjpgstreamer -n

Explicitly USB device: 
-----------------------------------------------

Found video devices:
/dev/video0
/dev/video1
/dev/video10
/dev/video11
/dev/video12
/dev/video13
/dev/video14
/dev/video15
/dev/video16
/dev/video18
/dev/video20
/dev/video21
/dev/video22
/dev/video23
/dev/video31
Scan again in two minutes
/usr/local/bin/webcamd: line 103: kill: (1196) - No such process

Goodbye...

/var/log/syslog:

Jul 17 10:29:55 ender-3s1 systemd[1]: Starting the FluiddPI webcam daemon (based on OctoPi) with the user specified config...
Jul 17 10:31:25 ender-3s1 systemd[1]: webcamd.service: start operation timed out. Terminating.
Jul 17 10:31:25 ender-3s1 systemd[1]: webcamd.service: Failed with result 'timeout'.
Jul 17 10:31:25 ender-3s1 systemd[1]: Failed to start the FluiddPI webcam daemon (based on OctoPi) with the user specified config.
Jul 17 10:31:26 ender-3s1 systemd[1]: webcamd.service: Scheduled restart job, restart counter is at 5.
Jul 17 10:31:26 ender-3s1 systemd[1]: Stopped the FluiddPI webcam daemon (based on OctoPi) with the user specified config.
### Windows users: To edit this file use Notepad++, VSCode, Atom or SublimeText.
### Do not use Notepad or WordPad.

### MacOSX users: If you use Textedit to edit this file make sure to use 
### "plain text format" and "disable smart quotes" in "Textedit > Preferences"

### Configure which camera to use
#
# Available options are:
# - auto: tries first usb webcam, if that's not available tries raspi cam
# - usb: only tries usb webcam
# - raspi: only tries raspi cam
#
# Defaults to auto
#
camera="raspi"

### Additional options to supply to MJPG Streamer for the RasPi Cam
#
# See https://faq.octoprint.org/mjpg-streamer-config for available options
#
# Defaults to 10fps
#
camera_raspi_options="--width 1280 --height 720 --framerate 60 -quality 100"

After changing camera="raspi" to camera="auto" I get the following issue:

config file='/home/pi/klipper_config/webcam.txt':USB device was not set in options, start MJPG-streamer with the first found video device: /dev/video0
/usr/local/bin/webcamd: line 184: printf: 0x: invalid hex number
/usr/local/bin/webcamd: line 184: printf: 0x: invalid hex number
<13>Jul 17 10:56:50 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 -i input_uvc.so -r 640x480 -f 10 -d /dev/video0
MJPG Streamer Version: git rev: 310b29f4a94c46652b20c4b7b6e5cf24e532af39
 i: Using V4L2 device.: /dev/video0
 i: Desired Resolution: 640 x 480
 i: Frames Per Second.: 10
 i: Format............: JPEG
 i: TV-Norm...........: DEFAULT
 i: Could not obtain the requested pixelformat: MJPG , driver gave us: YUYV
    ... will try to handle this by checking against supported formats. 
    ... Falling back to YUV mode (consider using -yuv option). Note that this requires much more CPU power
Unable to query that the FPS change is supported
: Inappropriate ioctl for device
UVCIOC_CTRL_ADD - Error at Pan (relative): Inappropriate ioctl for device (25)
UVCIOC_CTRL_ADD - Error at Tilt (relative): Inappropriate ioctl for device (25)
UVCIOC_CTRL_ADD - Error at Pan Reset: Inappropriate ioctl for device (25)
UVCIOC_CTRL_ADD - Error at Tilt Reset: Inappropriate ioctl for device (25)
UVCIOC_CTRL_ADD - Error at Pan/tilt Reset: Inappropriate ioctl for device (25)
UVCIOC_CTRL_ADD - Error at Focus (absolute): Inappropriate ioctl for device (25)
UVCIOC_CTRL_MAP - Error at Pan (relative): Inappropriate ioctl for device (25)
UVCIOC_CTRL_MAP - Error at Tilt (relative): Inappropriate ioctl for device (25)
UVCIOC_CTRL_MAP - Error at Pan Reset: Inappropriate ioctl for device (25)
UVCIOC_CTRL_MAP - Error at Tilt Reset: Inappropriate ioctl for device (25)
UVCIOC_CTRL_MAP - Error at Pan/tilt Reset: Inappropriate ioctl for device (25)
UVCIOC_CTRL_MAP - Error at Focus (absolute): Inappropriate ioctl for device (25)
UVCIOC_CTRL_MAP - Error at LED1 Mode: Inappropriate ioctl for device (25)
UVCIOC_CTRL_MAP - Error at LED1 Frequency: Inappropriate ioctl for device (25)
UVCIOC_CTRL_MAP - Error at Disable video processing: Inappropriate ioctl for device (25)
UVCIOC_CTRL_MAP - Error at Raw bits per pixel: Inappropriate ioctl for device (25)
 o: www-folder-path......: ./www-mjpgstreamer/
 o: HTTP TCP port........: 8080
 o: HTTP Listen Address..: (null)
 o: username:password....: disabled
 o: commands.............: disabled
libv4l2: error turning on stream: Invalid argument
Unable to start capture: Invalid argument
 i: Can't enable video in first time
 i: cleaning up resources allocated by input thread
Done bring up all configured video device

Goodbye...

Trying start MJPEG-Streamer with the provided command line gets the following error: ./mjpg_streamer -o output_http.so -w ./www-mjpgstreamer -n -i input_uvc.so -r 640x480 -f 10 -d /dev/video0

pi@ender-3s1:~/mjpg-streamer $ ./mjpg_streamer -o output_http.so -w ./www-mjpgstreamer -n -i input_uvc.so -r 640x480 -f 10 -d /dev/video0
./mjpg_streamer: invalid option -- 'w'
-----------------------------------------------------------------------
Usage: ./mjpg_streamer
  -i | --input "<input-plugin.so> [parameters]"
  -o | --output "<output-plugin.so> [parameters]"
 [-h | --help ]........: display this help
 [-v | --version ].....: display version information
 [-b | --background]...: fork to the background, daemon mode
-----------------------------------------------------------------------
Example #1:
 To open an UVC webcam "/dev/video1" and stream it via HTTP:
  ./mjpg_streamer -i "input_uvc.so -d /dev/video1" -o "output_http.so"
-----------------------------------------------------------------------
Example #2:
 To open an UVC webcam and stream via HTTP port 8090:
  ./mjpg_streamer -i "input_uvc.so" -o "output_http.so -p 8090"
-----------------------------------------------------------------------
Example #3:
 To get help for a certain input plugin:
  ./mjpg_streamer -i "input_uvc.so --help"
-----------------------------------------------------------------------
In case the modules (=plugins) can not be found:
 * Set the default search path for the modules with:
   export LD_LIBRARY_PATH=/path/to/plugins,
 * or put the plugins into the "/lib/" or "/usr/lib" folder,
 * or instead of just providing the plugin file name, use a complete
   path and filename:
   ./mjpg_streamer -i "/path/to/modules/input_uvc.so"
-----------------------------------------------------------------------

After changing ./mjpg_streamer -o output_http.so -w ./www-mjpgstreamer -n -i input_uvc.so -r 640x480 -f 10 -d /dev/video0 to ./mjpg_streamer -o "output_http.so -w ./www-mjpgstreamer -n" -i "input_uvc.so -r 640x480 -f 10 -d /dev/video0" MJPEG-Streamer starts and I get a live stream inside Fluidd - great!

The Issue was, the argument -o and -i needs to be inside quotation marks. But this is a trap! As seen in the follow lines, only the echo output is wrong. If you echo a string with quotation marks you need to escape the quotation marks with a backslash character. https://github.com/fluidd-core/FluiddPI/blob/7c73dcc8832b5284b102a3a2c8781b53c550d907/src/modules/mjpgstreamer/filesystem/root/usr/local/bin/webcamd#L149-L155

But this don't fix anything, because the character escape only affect the log files and not the mjpg_streamer execution.

After checking my /boot/config.txt file, I recognized the following lines:

# Automatically load overlays for detected cameras
start_x=1
gpu_mem=128
camera_auto_detect=1
dtoverlay=imx219

Normally after running raspi-config and enabling Legacy Camera this two lines need to disappear:

camera_auto_detect=1
dtoverlay=imx219

Comment it out or delete the lines and reboot. As you see, the cam is online! But our raspi options did not apply: --width 1280 --height 720 --framerate 60 -quality 100 To change the resolution we need to modify the webcam.txt again, but this time under the USB webcams (input_uvc.so) section:

### Configure which camera to use
#
# Available options are:
# - auto: tries first usb webcam, if that's not available tries raspi cam
# - usb: only tries usb webcam
# - raspi: only tries raspi cam
#
# Defaults to auto
#
camera="usb"

### Additional options to supply to MJPG Streamer for the USB camera
#
# See https://faq.octoprint.org/mjpg-streamer-config for available options
#
# Defaults to a resolution of 640x480 px and a framerate of 10 fps
#
camera_usb_options="-r 1280x720 -f 60 -q 100"

Keep in mind, the arguments are slightly different. Here you get it all: Octoprint mjpeg streamer config options

For now, here I stop my research. The webcam is working and the custom mjpeg settings are applied. The next steps are upgrading mjpeg-streamer to using the new libcamera stack.