Unable to connect to Raspberry Pi camera on Zero W after OS update

I have a minimal python-based camera project that’s been running fine since the last summer. The thing takes time-lapse photos based on environmental conditions (sun’s position, detected brightness, etc.) and uploads them to a server for later processing. It is based on the (now rather old) raspi camera sample: GitHub - balena-io-playground/balena-rpi-python-picamera: balena + python + raspberry pi camera module

I updated BalenaOS to the latest version on this device (raspi zero w) and now the project container is failing to start with the following error message:

modprobe: FATAL: Module v4l2_common not found in directory /lib/modules/5.10.31

This error is obviously coming from the original sample project’s run command that I also copied over without honestly really understanding why it’s needed in this case:

CMD modprobe v4l2_common && python camera.py

Running the modprobe command via remote SSH gives the same error and indeed the /lib/modules/5.10.31 directory has nothing pointing to v4l2.

I’ve tried to research the v4l2 lib, but can’t find an up-to-date discussion about a similar issue. My best guess is that a previous version of BalenaOS contained the video4linux drivers, but something around that has now changed. Ctrl+f on the OS patch notes didn’t give any hints. I am very much out of my depth when it comes to Linux drivers and tried installing the v4l-utils package without results.

Any tips on what to try next? I’m okay with completely resetting the device if needed.

My full Dockerfile (functionally identical to the official sample and worked till the OS update as-is):

FROM balenalib/%%BALENA_MACHINE_NAME%%-python

COPY ./requirements.txt /requirements.txt
RUN READTHEDOCS=True pip install -r /requirements.txt

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

CMD modprobe v4l2_common && python camera.py

All input much appreciated, thanks!

1 Like

Hello @Haila welcome to the balena community!

What OS version were you using before? What OS are you using now?

If you can’t make it run, as a last alternative you could download the older OS image and reprovision the device on your fleet?

BTW @Haila i found here the same issue and potential solution → RPI3 bullseye image and libcamera - #14 by rahul-thakoor

Let me know if that works :slight_smile:

Hey @Haila

Did you find a fix for this?

Hi @mpous and @Jazzagi,

Thanks for checking in. The linked thread is actually about a different error, but provided some interesting clues.

I believe the example project that I based my camera app on is now woefully out of date: GitHub - balena-io-playground/balena-rpi-python-picamera: balena + python + raspberry pi camera module

For some reason updating my Raspi Zero’s BalenaOS to “2.83.21+rev1” broke the code as per my original post. Unfortunately I don’t know what my previous OS version was and the whole device dropped offline soon after I remotely shut down all services to prevent it from crash looping for days. Maybe the SD card filled up and prevents booting now.

I think I have two ways forward:

  1. Downgrade to OS to something from last summer until it works. Not ideal for obvious long-term reasons.

  2. Rewrite the Python app to use the upcoming (and still experimental) picamera2 library that is based on the same, new libcamera library used in the new official tutorial that was posted a month ago and mentioned in the other bug thread: GitHub - balena-io-playground/libcamera-apps: Example repo to showcase Raspberry Pi's new libcamera stack on balenaOS

Unfortunately, my physical device is deployed far out on the field and it will take me a few weeks at least to get a full repro on the Zero hardware, but I’ll try this approach on another Pi model hopefully soon. I’ll report back on the results.

To anyone curious, the use case is this: https://homelab.haila.fi/after-sunrise

Might I suggest removing the outdated picamera Python sample code in case someone else bumps into this same issue? I’m happy to share a working version of mine after I get it rewritten on top of picamera2 :slight_smile:

1 Like

Update to anyone stumbling on this later: downgrading to the “balenaOS 2.54.2+rev1” OS version works. I tested on a fresh Raspi 1.2 B+ that the latest OS gives the same error as above and downgrading resolves it.

I will still experiment later if the picamera2 route works with the latest OS, but unfortunately, it’s so so much in alpha stages that I might give it a months or two. Even just the installation is quite involved for now.

1 Like

Thanks @Haila for confirming that it works with balenaOS 2.54.2+rev1.