mryel00 / spyglass

A simple mjpeg server for Picamera2
GNU General Public License v3.0
70 stars 15 forks source link

run.py camera init sequence did not complete failed to acquire camera #74

Closed B1ueOne closed 5 months ago

B1ueOne commented 5 months ago
pi@VzBot:~ $ spyglass/run.py
INFO:root:Spyglass 0.13.0
[0:11:41.291767898] [1709]  INFO Camera camera_manager.cpp:297 libcamera v0.0.5+83-bde9b04f
[0:11:41.321646339] [1710]  INFO RPI vc4.cpp:437 Registered camera /base/soc/i2c0mux/i2c@1/imx708@1a to Unicam device /dev/media0 and ISP device /dev/media2
[0:11:41.321728469] [1710]  INFO RPI pipeline_base.cpp:1101 Using configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'
INFO:picamera2.picamera2:Initialization successful.
[0:11:41.324097467] [1709]  INFO Camera camera.cpp:840 Pipeline handler in use by another process
ERROR:picamera2.picamera2:Camera __init__ sequence did not complete.
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 242, in __init__
    self._open_camera()
  File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 446, in _open_camera
    self.camera.acquire()
RuntimeError: Failed to acquire camera: Device or resource busy

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/spyglass/run.py", line 6, in <module>
    raise SystemExit(main())
  File "/home/pi/spyglass/spyglass/cli.py", line 44, in main
    picam2 = init_camera(
  File "/home/pi/spyglass/spyglass/camera.py", line 26, in init_camera
    picam2 = Picamera2(tuning=tuning)
  File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 254, in __init__
    raise RuntimeError("Camera __init__ sequence did not complete.")
RuntimeError: Camera __init__ sequence did not complete.

I have just switched from crowsnest to spyglass and when I run the script I get the above. Help is much appreciated. I'm trying to get my pi cam v3 wide to work on my printer

B1ueOne commented 5 months ago

Solved after reinstalling crowsnest and uninstalling it by hand. However, a new issue arose:

pi@VzBot:~/spyglass $ ./run.py
INFO:root:Spyglass 0.13.0
[0:02:37.188917217] [1155]  INFO Camera camera_manager.cpp:297 libcamera v0.0.5+83-bde9b04f
[0:02:37.316100892] [1156]  INFO RPI vc4.cpp:437 Registered camera /base/soc/i2c0mux/i2c@1/imx708@1a to Unicam device /dev/media2 and ISP device /dev/media1
[0:02:37.316605564] [1156]  INFO RPI pipeline_base.cpp:1101 Using configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'
INFO:picamera2.picamera2:Initialization successful.
INFO:picamera2.picamera2:Camera now open.
INFO:picamera2.picamera2:Camera configuration has been adjusted!
[0:02:37.328393924] [1155]  INFO Camera camera.cpp:1033 configuring streams: (0) 640x480-XBGR8888 (1) 1536x864-SBGGR10_CSI2P
[0:02:37.329237919] [1156]  INFO RPI vc4.cpp:565 Sensor: /base/soc/i2c0mux/i2c@1/imx708@1a - Selected sensor format: 1536x864-SBGGR10_1X10 - Selected unicam format: 1536x864-pBAA
INFO:picamera2.picamera2:Configuration successful!
[0:02:38.429764305] [1156] ERROR V4L2 v4l2_videodevice.cpp:1906 /dev/video1[17:cap]: Failed to start streaming: Input/output error
Traceback (most recent call last):
  File "/home/pi/spyglass/./run.py", line 6, in <module>
    raise SystemExit(main())
  File "/home/pi/spyglass/spyglass/cli.py", line 58, in main
    picam2.start_recording(MJPEGEncoder(), FileOutput(output))
  File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 1598, in start_recording
    self.start()
  File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 1055, in start
    self.start_()
  File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 1023, in start_
    self.camera.start(controls)
RuntimeError: Failed to start camera: Input/output error

this time it's getting stuck at ERROR V4L2 v4l2_videodevice.cpp:1906 /dev/video1[17:cap]: Failed to start streaming: Input/output error

mryel00 commented 5 months ago

Stop crowsnest.

Failed to acquire camera: Device or resource busy

That means the cam is currently used by a different service. I'm wondering, why you swapped from crowsnest to spyglass.

B1ueOne commented 5 months ago

Stop crowsnest.

Failed to acquire camera: Device or resource busy

That means the cam is currently used by a different service. I'm wondering, why you swapped from crowsnest to spyglass.

Because I can't get my pi cam v3 to work with crowsnest, no matter what I try

mryel00 commented 5 months ago
RuntimeError: Failed to start camera: Input/output error

This indicates that you ase using a touchscreen and a cam. Those won't work well together. This issue should be fixed for some instances on Bookworm.

mryel00 commented 5 months ago

Because I can't get my pi cam v3 to work with crowsnest, no matter what I try

This won't be different with spyglass then, as you already saw with the new issue.

B1ueOne commented 5 months ago

I've uninstalled KlipperScreen and Crowsnest completely, however I'm still getting the same errors.

Either it's RuntimeError: Failed to start camera: Input/output error if I have dtoverlay=vc4-fkms-v3d or it changes to Failed to acquire camera: Device or resource busy when I have dtoverlay=vc4-kms-v3d

mryel00 commented 5 months ago

Disconnect the screen. Changing the mentioned dtoverlay will most likely activate and deactivate touch and rotation of the screen. No idea why you get the resource busy, but it's like I said, it signals that something else is using the cam. Maybe you got the spyglass service installed?

B1ueOne commented 5 months ago

I physically disconnected the screen as you suggested, no change sadly.

I installed spyglass as described with:

cd ~/spyglass
make install

and added the following to my moonraker.conf:

[update_manager spyglass]
type: git_repo
channel: beta
path: ~/spyglass
origin: https://github.com/roamingthings/spyglass.git
managed_services: spyglass

Not sure what I could have done wrong here

mryel00 commented 5 months ago

Just to be sure run the following commands and get me the output of each one.

sudo systemctl stop crowsnest
sudo systemctl disable crowsnest
sudo systemctl stop spyglass
~/spyglass/run.py

Also send your `/boot/config.txt

B1ueOne commented 5 months ago
pi@VzBot:~ $ sudo systemctl stop crowsnest
Failed to stop crowsnest.service: Unit crowsnest.service not loaded.
pi@VzBot:~ $ sudo systemctl disable crowsnest
Failed to disable unit: Unit file crowsnest.service does not exist.
pi@VzBot:~ $ sudo systemctl stop spyglass
pi@VzBot:~ $ ~/spyglass/run.py
INFO:root:Spyglass 0.13.0
[0:05:48.038263421] [1309]  INFO Camera camera_manager.cpp:297 libcamera v0.0.5+83-bde9b04f
[0:05:48.155918024] [1310]  INFO RPI vc4.cpp:437 Registered camera /base/soc/i2c0mux/i2c@1/imx708@1a to Unicam device /dev/media4 and ISP device /dev/media1
[0:05:48.156080714] [1310]  INFO RPI pipeline_base.cpp:1101 Using configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'
INFO:picamera2.picamera2:Initialization successful.
INFO:picamera2.picamera2:Camera now open.
INFO:picamera2.picamera2:Camera configuration has been adjusted!
[0:05:48.170754744] [1309]  INFO Camera camera.cpp:1033 configuring streams: (0) 640x480-XBGR8888 (1) 1536x864-SBGGR10_CSI2P
[0:05:48.171332178] [1310]  INFO RPI vc4.cpp:565 Sensor: /base/soc/i2c0mux/i2c@1/imx708@1a - Selected sensor format: 1536x864-SBGGR10_1X10 - Selected unicam format: 1536x864-pBAA
INFO:picamera2.picamera2:Configuration successful!
INFO:picamera2.picamera2:Camera started
INFO:spyglass:Server listening on 0.0.0.0:8080
INFO:spyglass:Streaming endpoint: /stream
INFO:spyglass:Snapshot endpoint: /snapshot
[0:05:48.617443945] [1310] ERROR V4L2 v4l2_device.cpp:353 'imx708_wide': Unable to set controls: Input/output error
127.0.0.1 - - [25/May/2024 19:16:16] code 501, message Unsupported method ('POST')
127.0.0.1 - - [25/May/2024 19:16:16] "POST /stream HTTP/1.0" 501 -
[0:05:49.481436262] [1310]  WARN V4L2 v4l2_videodevice.cpp:2007 /dev/video0[16:cap]: Dequeue timer of 1000000.00us has expired!
[0:05:49.481565992] [1310] ERROR RPI pipeline_base.cpp:1333 Camera frontend has timed out!
[0:05:49.481589027] [1310] ERROR RPI pipeline_base.cpp:1334 Please check that your camera sensor connector is attached securely.
[0:05:49.481609155] [1310] ERROR RPI pipeline_base.cpp:1335 Alternatively, try another cable and/or sensor.
127.0.0.1 - - [25/May/2024 19:16:23] code 501, message Unsupported method ('POST')
127.0.0.1 - - [25/May/2024 19:16:23] "POST /stream HTTP/1.0" 501 -
127.0.0.1 - - [25/May/2024 19:16:30] code 501, message Unsupported method ('POST')
127.0.0.1 - - [25/May/2024 19:16:30] "POST /stream HTTP/1.0" 501 -
^CINFO:picamera2.picamera2:Camera stopped
Traceback (most recent call last):
  File "/home/pi/spyglass/run.py", line 6, in <module>
    raise SystemExit(main())
  File "/home/pi/spyglass/spyglass/cli.py", line 61, in main
    run_server(bind_address, port, output, stream_url, snapshot_url, orientation_exif)
  File "/home/pi/spyglass/spyglass/server.py", line 100, in run_server
    current_server.serve_forever()
  File "/usr/lib/python3.9/socketserver.py", line 232, in serve_forever
    ready = selector.select(poll_interval)
  File "/usr/lib/python3.9/selectors.py", line 416, in select
    fd_event_list = self._selector.poll(timeout)
KeyboardInterrupt

pi@VzBot:~ $
# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on

# Uncomment this to enable infrared communication.
#dtoverlay=gpio-ir,gpio_pin=17
#dtoverlay=gpio-ir-tx,gpio_pin=18

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
dtparam=audio=on

# Automatically load overlays for detected cameras
camera_auto_detect=1

# Automatically load overlays for detected DSI displays
display_auto_detect=1

# Enable DRM VC4 V3D driver
dtoverlay=vc4-fkms-v3d
max_framebuffers=2

# Run in 64-bit mode
arm_64bit=1

# Disable compensation for displays with overscan
disable_overscan=1

[cm4]
# Enable host mode on the 2711 built-in XHCI USB controller.
# This line should be removed if the legacy DWC2 controller is required
# (e.g. for USB device mode) or if USB support is not required.
otg_mode=1

[all]

[pi4]
# Run as fast as firmware / board allows
arm_boost=1

[all]

####################################################
####     MainsailOS specific configurations     ####
####################################################
####      DO NOT CHANGE SECTION BELOW !!!       ####
####   UNLESS YOU KNOW WHAT YOU ARE DOING !!!   ####
####################################################

## For more options and information see
## https://www.raspberrypi.com/documentation/computers/config_txt.html
## Some settings may impact device functionality. See link above for details

## For additional information about device filters see
## https://www.raspberrypi.com/documentation/computers/config_txt.html#model-filters

[pi0]
## This affects Pi Zero(W) and Pi Zero2
## Due lag of RAM, limit GPU RAM
gpu_mem=256

[pi2]
gpu_mem=256

[pi3]
## Use 256 if 1Gb Ram Model!
gpu_mem=256

[pi4]
## Do not use more than 256Mb on Pi Model 4, it uses its own Management.
gpu_mem=256

[all]

## SPI Interface is enabled by default for Input Shaper
## This colides with Hyperpixel Display!
## Hyperpixel Screen uses the same Pin for Backlight.
dtparam=spi=on

## Enable Hardware UART for Serial Communication
## This also disables Bluetooth!
enable_uart=1
dtoverlay=disable-bt

## Enable I2C by default.
## This is used by Klipper's Host MCU
## See https://www.klipper3d.org/RPi_microcontroller.html#optional-enabling-i2c
## for destails.
## For MPU Accelrometer please use
## dtparam=i2c_arm=on,i2c_arm_baudrate=400000
dtparam=i2c_arm=on

### EXPERIMENTAL - Enable 64bit Kernel
### The 64-bit kernel will only work on:
### Raspberry Pi 3, 3+, 4, 400, Zero 2 W and 2B rev 1.2
### and Raspberry Pi Compute Modules 3, 3+ and 4.
# arm_64bit=1

####################################################

[all]
dtoverlay=imx708_wide
#dtoverlay=imx708
mryel00 commented 5 months ago

Delete the last two lines from your /boot/config.txt. The run command shows that it's working as intended, so start the spyglass service again with sudo systemctl start spyglass. Then edit the spyglass.conf in your webui to either use the default urls of your UI or use the default urls of spyglass to add them in the UI, as described here

B1ueOne commented 5 months ago

My spyglass.conf looks like this:

#### spyglass - Picamera2 MJPG Streamer
####
#### https://github.com/roamingthings/spyglass
####
#### This File is distributed under GPLv3
####

#### NOTE: Please ensure parameters are in capital letters and values in lowercase!
#### NOTE: Values has to be surrounded by double quotes! ("value")
#### NOTE: If commented out or includes typos it will use hardcoded defaults!

#### Running Spyglass with proxy or Standalone (BOOL)[default: true]
NO_PROXY="true"

#### HTTP Port to listen on (INTEGER)[default: 8080]
HTTP_PORT="8080"

#### Resolution (INTEGERxINTEGER)[default: 640x480]
RESOLUTION="640x480"
#### NOTE: the maximum supported resolution is 1920x1920 (recommended maximum 1920x1080)

#### Frames per second (INTEGER)[default: 15]
FPS="15"

#### Stream URL (STRING)[default: /stream]
STREAM_URL="/?action=stream
#### NOTE: use format as shown below to stay MJPG-Streamer URL compatible
## STREAM_URL="/?action=stream"

#### Snapshot URL (STRING)[default: /snapshot]
SNAPSHOT_URL="/?action=snapshot"
#### NOTE: use format as shown below to stay MJPG-Streamer URL compatible
## SNAPSHOT_URL="/?action=snapshot"

#### Autofocus behavior (STRING:manual,continuous)[default: continuous]
AUTO_FOCUS="continuous"

#### Focal Distance (float:0.0)[default: 0.0]
#### NOTE: Set focal distance. 0 for infinite focus, 0.5 for approximate 50cm.
####       Only used with Autofocus manual
FOCAL_DIST="0.0"

#### Auto Focus Speed (STRING:normal,fast)[default: normal]
#### NOTE: Autofocus speed. Supported values: normal, fast.
####       Only used with Autofocus continuous
AF_SPEED="normal"

#### EXIF Orientation (STRING:h,mh,r180,mv,mhr270,r90,mhr90,r270)[default: h]
#### NOTE: Set the image orientation using an EXIF header.
####       h      - Horizontal (normal)
####       mh     - Mirror horizontal
####       r180   - Rotate 180
####       mv     - Mirror vertical
####       mhr270 - Mirror horizontal and rotate 270 CW
####       r90    - Rotate 90 CW
####       mhr90  - Mirror horizontal and rotate 90 CW
####       r270   - Rotate 270 CW
ORIENTATION_EXIF="h"

#### Tuning Filter Directory (STRING)[default: none]
#### NOTE: Directory where to search for tuning filters(if defined).
####       Directory only used if TUNING_FILTER is defined
# TUNING_FILTER_DIR="/usr/share/libcamera/ipa/raspberrypi"

#### Tuning Filter (STRING)[default: none]
#### NOTE: Name of the file to be used to apply tuning filter.
####       If dir not defined, default pycamera2 directories will be used.
# TUNING_FILTER="ov5647_noir.json"

I added the Webcam to the UI as described, however I only get a blank, white image

/webcam/?action=stream
/webcam/?action=snapshot
MJPEG-Streamer
mryel00 commented 5 months ago

There is a typo in your stream url

B1ueOne commented 5 months ago

It doesn't work either with

/?action=stream /?action=snapshot

if that is what you mean

mryel00 commented 5 months ago
#### Stream URL (STRING)[default: /stream]
STREAM_URL="/?action=stream
#### NOTE: use format as shown below to stay MJPG-Streamer URL compatible
## STREAM_URL="/?action=stream"

There is a typo in your config. There is a missing "

B1ueOne commented 5 months ago

Ah. Fixed it. However, I'm afraid it still only shows a blank white image. At this point I just want the camera to work any way possible. I've been at it all day trying to troubleshoot.

B1ueOne commented 5 months ago

The run command shows that it's working as intended, so start the spyglass service again with sudo systemctl start spyglass.

Are you sure? I still had errors in the text I've posted above:

[0:05:48.617443945] [1310] ERROR V4L2 v4l2_device.cpp:353 'imx708_wide': Unable to set controls: Input/output error
127.0.0.1 - - [25/May/2024 19:16:16] code 501, message Unsupported method ('POST')
127.0.0.1 - - [25/May/2024 19:16:16] "POST /stream HTTP/1.0" 501 -
[0:05:49.481436262] [1310]  WARN V4L2 v4l2_videodevice.cpp:2007 /dev/video0[16:cap]: Dequeue timer of 1000000.00us has expired!
[0:05:49.481565992] [1310] ERROR RPI pipeline_base.cpp:1333 Camera frontend has timed out!
[0:05:49.481589027] [1310] ERROR RPI pipeline_base.cpp:1334 Please check that your camera sensor connector is attached securely.
[0:05:49.481609155] [1310] ERROR RPI pipeline_base.cpp:1335 Alternatively, try another cable and/or sensor.
mryel00 commented 5 months ago

Oh I oversaw that somehow.... Then change dtoverlay=vc4-fkms-v3d to dtoverlay=vc4-kms-v3d

Also share what OS version you are using

B1ueOne commented 5 months ago

Sadly I have the same error with dtoverlay=vc4-kms-v3d

OS Version is:

PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 11 (bullseye)
Release:        11
Codename:       bullseye

Kernel: Linux 6.1.21-v8+
Architecture: arm64
B1ueOne commented 5 months ago

I have found the issue. It was a defective HDMI cable...