0

I'm trying to make a time lapse using crontab to manage time intervals. The camera I use is an arducam Autofocus imx519. The libcamera-still command works normally when run via terminal. But when I run the following script via crontab the line containing libcamera-still is not executed.

Here my python script with privileges u+x:

#!/usr/bin/python3

import os
import subprocess
from pijuice import PiJuice

pj = PiJuice(1,0x14)

# Get battery level and write statement to log
batteryLevel = pj.status.GetChargeLevel()
os.system("date=$(date); text=$(echo '    PICTURE    " + str(batteryLevel) + "'); echo $date$text >> ~/log")

# Get date and separate day and time
date = subprocess.getoutput("date +%F")
time = subprocess.getoutput("date +%H:%M")

# Take picture
out = os.system("libcamera-still -o ~/Pictures/"+date+"/"+time+".jpg --autofocus >> test.txt")
os.system("echo '" + str(out) + "' >> test.txt")

and my crontab for testing looks like this:

* * * * * ./script.py

The script is running, the logs are taken correctly, but the line containing libcamera-still is not running (no output written to test.txt). The line os.system("echo '" + str(out) + "' >> test.txt") always writes 32512 (and I don't know for what it stands for).

When I run the script via terminal ( $ ./script.py ) it works perfectly, it writes 0 to test.txt and returns the following lines:

Preview window unavailable
[11:47:51.665744000] [1201]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0
[11:47:51.715527000] [1212]  WARN CameraSensorProperties camera_sensor_properties.cpp:141 No static properties available for 'imx519'
[11:47:51.716860000] [1212]  WARN CameraSensorProperties camera_sensor_properties.cpp:143 Please consider updating the camera sensor properties database
[11:47:51.718001000] [1212] ERROR CameraSensor camera_sensor.cpp:551 'imx519 10-001a': Camera sensor does not support test pattern modes.
[11:47:51.852132000] [1212]  WARN RPI raspberrypi.cpp:1233 Mismatch between Unicam and CamHelper for embedded data usage!
[11:47:51.856864000] [1212] ERROR DelayedControls delayed_controls.cpp:87 Delay request for control id 0x009a090a but control is not exposed by device /dev/v4l-subdev0
[11:47:51.861199000] [1212]  INFO RPI raspberrypi.cpp:1356 Registered camera /base/soc/i2c0mux/i2c@1/imx519@1a to Unicam device /dev/media3 and ISP device /dev/media0
[11:47:51.866415000] [1201]  INFO Camera camera.cpp:1028 configuring streams: (0) 2328x1748-YUV420
[11:47:51.871248000] [1212]  INFO RPI raspberrypi.cpp:751 Sensor: /base/soc/i2c0mux/i2c@1/imx519@1a - Selected sensor format: 2328x1748-SRGGB10_1X10 - Selected unicam format: 2328x1748-pRAA
[11:47:51.983735000] [1219]  INFO IPARPI raspberrypi.cpp:666 Request ctrl: AfTrigger = 1
[11:47:51.985183000] [1219]  INFO IPARPI raspberrypi.cpp:666 Request ctrl: Saturation = 1.000000
[11:47:51.986450000] [1219]  INFO IPARPI raspberrypi.cpp:666 Request ctrl: Contrast = 1.000000
[11:47:51.987372000] [1219]  INFO IPARPI raspberrypi.cpp:666 Request ctrl: Brightness = 0.000000
[11:47:51.989790000] [1219]  INFO IPARPI raspberrypi.cpp:666 Request ctrl: AwbMode = 0
[11:47:51.991590000] [1219]  INFO IPARPI raspberrypi.cpp:666 Request ctrl: Sharpness = 1.000000
[11:47:51.993349000] [1219]  INFO IPARPI raspberrypi.cpp:666 Request ctrl: ExposureValue = 0.000000
[11:47:51.994819000] [1219]  INFO IPARPI raspberrypi.cpp:666 Request ctrl: AeExposureMode = 0
[11:47:51.995729000] [1219]  INFO IPARPI raspberrypi.cpp:666 Request ctrl: FrameDurationLimits = [ 33333, 33333 ]
[11:47:51.996677000] [1219]  INFO IPARPI raspberrypi.cpp:666 Request ctrl: AeMeteringMode = 0
[11:47:52.000276000] [1219]  INFO IPARPI raspberrypi.cpp:666 Request ctrl: NoiseReductionMode = 3
[11:47:57.258585000] [1201]  INFO Camera camera.cpp:1028 configuring streams: (0) 4656x3496-YUV420 (1) 4656x3496-SRGGB10_CSI2P
[11:47:57.267650000] [1212]  INFO RPI raspberrypi.cpp:751 Sensor: /base/soc/i2c0mux/i2c@1/imx519@1a - Selected sensor format: 4656x3496-SRGGB10_1X10 - Selected unicam format: 4656x3496-pRAA
[11:47:57.505010000] [1229]  INFO IPARPI raspberrypi.cpp:666 Request ctrl: AfTrigger = 1
[11:47:57.506463000] [1229]  INFO IPARPI raspberrypi.cpp:666 Request ctrl: Saturation = 1.000000
[11:47:57.507638000] [1229]  INFO IPARPI raspberrypi.cpp:666 Request ctrl: Contrast = 1.000000
[11:47:57.508547000] [1229]  INFO IPARPI raspberrypi.cpp:666 Request ctrl: Brightness = 0.000000
[11:47:57.511001000] [1229]  INFO IPARPI raspberrypi.cpp:666 Request ctrl: AwbMode = 0
[11:47:57.513578000] [1229]  INFO IPARPI raspberrypi.cpp:666 Request ctrl: Sharpness = 1.000000
[11:47:57.516040000] [1229]  INFO IPARPI raspberrypi.cpp:666 Request ctrl: ExposureValue = 0.000000
[11:47:57.517747000] [1229]  INFO IPARPI raspberrypi.cpp:666 Request ctrl: AeExposureMode = 0
[11:47:57.519464000] [1229]  INFO IPARPI raspberrypi.cpp:666 Request ctrl: FrameDurationLimits = [ 100, 1000000000 ]
[11:47:57.520646000] [1229]  INFO IPARPI raspberrypi.cpp:666 Request ctrl: AeMeteringMode = 0
[11:47:57.520991000] [1229]  INFO IPARPI raspberrypi.cpp:666 Request ctrl: NoiseReductionMode = 2
Still capture image received

I already tried to change the paths of the command in crontab unsuccessfully.
I also tried to run os.system("cd /home/pi && libcamera-still ...") with no success.

Any hints or ideas where the problem could be or how can I fix it?
Many thanks in advance for you possible answer!!

2
  • Why not manage the time intervals in your Python code - much easier?
    – CoderMike
    May 13 at 7:38
  • I tought but I can't do like you said because the power source is a battery and solar cell: if by bad luck the battery dries out it is much harder to make everything work again correctly
    – Pa Dalton
    May 13 at 7:43

1 Answer 1

0

The fix was really siple:
First run via terminal which libcamera-still
I got: /usr/local/bin/libcamera-still
Then write os.system("/usr/local/bin/libcamera-still ...") instead of os.system("libcamera-still ...").

Works like a charm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.