-1

Does not save photos using auto-launch in crontab. I use Python 3 or raspistill, they work well for photos when a monitor is connected.

    #!/usr/bin/python3
    # BEFORE USING THIS SCRIPT.
    # mkdir ~/timelapse 
    # mkdir ~/timelapse/completed
    # this file should live in ~/timelapse and is run with command "python3 ~/timelapse/timelapse.py
    
    import time
    from picamera import PiCamera
    from os import system
    
    camera = PiCamera()
    camera.resolution = (1920, 1080)
    
    SleepTimeL = 1
    FrameCount = 0
    FrameStop = 240
    
    WAIT = int(FrameStop)*int(SleepTimeL)/60
    
    print('Photography will take approximately ' + str(WAIT) + ' minutes')
    print('Taking photos now')
    while (FrameCount < FrameStop):
        print('Picture:' + str(FrameCount) + ' of ' + str(FrameStop))
        camera.capture('image' + str(FrameCount).zfill(4) + '.jpg')
        time.sleep(SleepTimeL);
        FrameCount = FrameCount + 1
    print('done')

and Bash script

#!/bin/bash

DATE=$(date +"%Y-%m-%d_%H%M")

raspistill -o /home/pi/camera/$DATE.jpg

I crate mkdir timelapse, cd ./timelapse; mkdir and file camera.sh After at Crontab, I did two different things not at same time. The first one I used: @reboot python3 /home/pi/timelapse/timelape.py & . The first one I used the second: * * * * * /home/pi/camera.sh 2>&1 . Both cases wrote crontab: installing new crontab. Turn off, turn on only with power without monitor. I thought they worked, the green light flashed.

Whether to add to the script to store photos?

2 Answers 2

1

It's been a while since I've used raspistill, but this may work as a cron job:

Create your bash script at /home/pi/camera.sh as follows:

#!/bin/bash
DATE=$(date +"%Y-%m-%d_%H%M")
/usr/bin/raspistill -o /home/pi/camera/$DATE.jpg

Be sure to mark it as executable :

chmod a+x /home/pi/camera.sh

Add the following line to your crontab (crontab -e):

* * * * *  /home/pi/camera.sh 2> /home/pi/camera/cronerrors.txt

This will run the cron job once per minute. If you want to use other schedules, you can find help from the crontab guru. The redirect here is different: only stderr is redirected.

Please verify this works (the bash script as a cron job), or post the contents of /home/pi/camera/cronerrors.txt otherwise. Once we've got this working, we can take on the Python script if you'd like.

0

You can create a service to run shell script, instead of @reboot in crontab.

Like this

https://github.com/mohdismailj/fancontrol/blob/main/fancontrol.service

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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