Set state of DSI/CAM1 switch

I can see you’ve also made an issue in the original balena cam repo;
With respect you the error:

22.05.20 15:20:39 (+0400)  balena-cam  select timeout
22.05.20 15:20:39 (+0400)  balena-cam  VIDIOC_DQBUF: Resource temporarily unavailable
22.05.20 15:20:39 (+0400)  balena-cam  Failed to open default camera. Exiting...

It seems like open cv cannot capture frames from the second device (assuming you are using cv2.VideoCapture(1))
Can you confirm which camera you are using?

Hi @rahul-thakoor,

I changed /dev/video0 to dev/video1 which fixed the driver error. I can also confirm that I am using cv2.VideoCapture(1). However, I am now back to this error:

balena-cam select timeout
balena-cam VIDIOC_DQBUF: Resource temporarily unavailable
balena-cam Failed to open default camera. Exiting…

Hi

  • Can you confirm which camera you are using?
  • Also, can you change the dockerfile that you push in balena-cam to start a python http server instead of running the server.py command? This is on the last line of the dockerfile in the balena-cam folder. This will allow us to access the container, and stop it from going into a reboot loop. One can start a python3 http server using python -m http.server

Hi,

Its done.

Hi there, the container appears to be in an invalid state, it is crash-looping with:

25.05.20 14:21:41 (-0700)  balena-cam  /usr/bin/python3: can't open file 'python -m http.server': [Errno 2] No such file or directory

In your Dockerfile it looks like you have python3 python -m http.server, which is incorrect.

Please change it to python3 -m http.server and rebuild.

So your last line in the Dockerfile should read:

CMD python3 -m http.server

I made the correction. It should be working fine now.

Glad you got it working!

I can confirm that it’s not crash-looping anymore - we will take a look at the application and see if we can gain more insight.

One thing that would help with investigations - would you be able to send us a couple of photos of the hardware setup? :

  • A photo of how the camera is connected
  • A photo of the dual camera switch
    Thank you

Hi,

Here are photos of the hardware setup.

Hi

  • Thanks for sharing the photos - everything looks correct to me.
  • One thing that I just wanted to ensure - have you tried swapping the cameras and verifying that both work? For the off chance that we have a faulty camera situation.

Thanks for keeping the device online, I am still trying some things out.

I thought of that as well. Both cameras work on the CAM0 port.

This is what my test setup looks like -

FROM balenalib/%%BALENA_MACHINE_NAME%%-debian:stretch-20190612

# Install dependencies
RUN apt-get update && \
  apt-get install -yq \
    python3 \
    python3-dev \
    python3-pip \
    python3-setuptools \
    gstreamer-1.0 \
    v4l-utils \
    libopus-dev \
    libvpx-dev \
    libsrtp2-dev \
    libopencv-dev \
    libatlas3-base \
    libatlas-base-dev \
    libjasper-dev \
    libilmbase12 \
    libopenexr22 \
    libavformat-dev \
    libswscale-dev \
    libqtgui4 \
    libqt4-test \
    libavdevice-dev \
    libavfilter-dev \
    libavcodec-dev \
  && apt-get clean && rm -rf /var/lib/apt/lists/*

# Enable the v4l2 driver for the Raspberry Pi camera
#RUN printf "bcm2835-v4l2\n" >> /etc/modules
RUN pip3 install --upgrade pip
RUN pip3 install async-timeout
RUN pip3 install aiohttp aiohttp_basicauth==0.1.3 aioice==0.6.10 aiortc==0.9.11 numpy==1.15.4 opencv-python==3.4.4.19 --index-url https://www.piwheels.org/simple
RUN pip3 install av
CMD modprobe bcm2835-v4l2
WORKDIR /usr/src/app

COPY ./app/ /usr/src/app/

# CMD ["python3", "/usr/src/app/server.py"]
CMD python3 -m http.server

I have made two changes to the dockerfile in balena-cam -

  1. I have added modprobe
  2. I have changed the last line to something that will give me access to the service and files instead of it actually starting the balena-cam application

Once I ssh to the service, I run the following and I get the desired output

root@f58b4c1:/usr/src/app# i2cdetect -y 3
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          03 -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- UU -- -- -- -- -- UU -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
root@f58b4c1:/usr/src/app#
root@f58b4c1:/usr/src/app# raspistill -o cam0.jpg
root@f58b4c1:/usr/src/app# raspistill -cs 1 -o cam1.jpg
root@f58b4c1:/usr/src/app# ls
cam0.jpg  cam1.jpg  client  server.py
root@f58b4c1:/usr/src/app#

Can you confirm that you have the same setup? Especially the dockerfile?

Same hardware setup. Docker file missing one line: CMD modprobe bcm2835-v4l2.

Hi

  • Did you check if adding that line to the Dockerfile fixes it? Make sure to use the raspistill command
  • Please share the exact make of your cameras. I have the Rpi Camera v2.1 in my setup above
  • If the fix in the Dockerfile doesn’t work, I think the next thing to do would be to initiate the RMA process

Hi,

I changed the docker file and got this:

root@6000d30:/usr/src/app# raspistill -o cam0.jpg
root@6000d30:/usr/src/app# raspistill -cs 1 -o cam1.jpg
Camera control callback cmd=0x4f525245mmal: No data received from sensor. Check all connections, including the Sunny one on the camera board

I have Rpi Camera v2.1 as well:

Hi @hegazi,

Just to let you know we are initiating an RMA process for you and we’ll get in contact with you soon!

Best Regards,
Marios

1 Like