Tamu UOB
Posts: 6
Joined: Tue Sep 11, 2018 9:13 am

raspi taking photo on boot every day at 10past and 50past

Tue Sep 11, 2018 9:24 am

Hi I'm trying to make a code to get a raspi to take a photo on boot at 10 past the hour and 50 past the hour, I have tried a cron tab generator which will take a photo but won't be sequential and I can't get it to do it from boot, I'm a compleat novice at coding so any help would be greatly appreciated.

pcmanbob
Posts: 4458
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: raspi taking photo on boot every day at 10past and 50past

Tue Sep 11, 2018 10:00 am

Hi.

Assuming you have some code to take one picture when commanded, getting cron to call the program is simple.

I am however a little confused as you say you want to to take it on boot at 10 & 50 min past the hour ?

on boot would suggest you want it to just take your picture when the pi boots, were as you say you want it to take them twice and hour at 10 & 50 mins, which would suggest you want to take multiple pictures.

So first lets assume your picture taking program is located in" /home/pi " and is called " takepic.py "

so to take a picture at boot

Code: Select all

@reboot python /home/pi/takepic.py
now because cron runs very early in the boot process hardware may not be ready so you may have to add a short delay to allow the pi to finish booting before taking your picture like this

Code: Select all

@reboot sleep 20 && python  /home/pi/takepic.py

Now to take pictures at 10min past the hour

Code: Select all

10 * * * *  python /home/pi/takepic.py
if you want it to run only during certain hours then you would do it like this ( 8 am to 8pm )

Code: Select all

10 8-20 * * *  python /home/pi/takepic.py
and 50min past the hour will be similar

Code: Select all

50 * * * *  python /home/pi/takepic.py
if you want it to run only during certain hours then you would do it like this ( 8 am to 8pm )

Code: Select all

50 8-20 * * *  python /home/pi/takepic.py
of course the pictures taken at 10 & 50 min past the hours will only work correctly if the time is correctly set on your pi and they will not be taken at boot only at the allotted time.
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

Tamu UOB
Posts: 6
Joined: Tue Sep 11, 2018 9:13 am

Re: raspi taking photo on boot every day at 10past and 50past

Tue Sep 11, 2018 10:49 am

Hi sorry yes I want the script to run all day automatically once the pi has booted up. eg take a picture at 7:10 then 7:50. does cron run automatically or do I need a bit of extra code?

and I'm guessing it will be two bits of code one for the 10 past and a separate one for 50 past?

User avatar
RaTTuS
Posts: 10102
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: raspi taking photo on boot every day at 10past and 50past

Tue Sep 11, 2018 11:14 am

crontab -e

Code: Select all

10,50 * * * *  /path/to/correct/python /home/pi/takepic.py
is all you need
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

pcmanbob
Posts: 4458
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: raspi taking photo on boot every day at 10past and 50past

Tue Sep 11, 2018 11:14 am

Tamu UOB wrote:
Tue Sep 11, 2018 10:49 am
Hi sorry yes I want the script to run all day automatically once the pi has booted up. eg take a picture at 7:10 then 7:50. does cron run automatically or do I need a bit of extra code?

and I'm guessing it will be two bits of code one for the 10 past and a separate one for 50 past?
So you have your script that takes the picture and then exits I would hope.
So you just need cron to run this script for you at the appointed times as I explained in the examples , using 2 cron lines is easier and allows you to simply change one if you want.

but you could do it with just one line which would than start like this

Code: Select all

10,50 * * * *
which would take a picture at 10 & 50 min past the hours 24 hours a day.

cron runs automatically on pi boot so all you need to do is add the lines to the cron file using crontab -e not forgetting to add a blank line after your entries at the end of the file.
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

Tamu UOB
Posts: 6
Joined: Tue Sep 11, 2018 9:13 am

Re: raspi taking photo on boot every day at 10past and 50past

Tue Sep 11, 2018 11:19 am

Thank you I will give that a go, i have been using the raspstill command for taking a picture

Tamu UOB
Posts: 6
Joined: Tue Sep 11, 2018 9:13 am

Re: raspi taking photo on boot every day at 10past and 50past

Tue Sep 11, 2018 3:18 pm

so i put in the code 50 * * * * python /home/pi/Camera.py

and get the error

bash: 50: command not found

any ideas

DirkS
Posts: 9211
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: raspi taking photo on boot every day at 10past and 50past

Tue Sep 11, 2018 3:27 pm

Tamu UOB wrote:
Tue Sep 11, 2018 3:18 pm
so i put in the code 50 * * * * python /home/pi/Camera.py

and get the error

bash: 50: command not found

any ideas
That's the line that needs to go into the crontab.
Edit the table with

Code: Select all

crontab -e
Then put the above that line into the file. Save and Exit and wait until it's 10 to the hour...

Tamu UOB
Posts: 6
Joined: Tue Sep 11, 2018 9:13 am

Re: raspi taking photo on boot every day at 10past and 50past

Tue Sep 11, 2018 3:37 pm

how do i save and exit? silly question but i cant seem to do it

DirkS
Posts: 9211
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: raspi taking photo on boot every day at 10past and 50past

Tue Sep 11, 2018 3:47 pm

Tamu UOB wrote:
Tue Sep 11, 2018 3:37 pm
how do i save and exit? silly question but i cant seem to do it
Assuming you ended up in 'nano': <Control+X>Y<ENTER>
BTW: available key codes should be at the bottom of the editor window.

Tamu UOB
Posts: 6
Joined: Tue Sep 11, 2018 9:13 am

Re: raspi taking photo on boot every day at 10past and 50past

Tue Sep 11, 2018 3:54 pm

Thank you i was adding ^ to the line rather than pressing control

DirkS
Posts: 9211
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: raspi taking photo on boot every day at 10past and 50past

Tue Sep 11, 2018 3:59 pm

Tamu UOB wrote:
Tue Sep 11, 2018 3:54 pm
Thank you i was adding ^ to the line rather than pressing control
^ is often used as a symbol for control

pfletch101
Posts: 207
Joined: Sat Feb 24, 2018 4:09 am

Re: raspi taking photo on boot every day at 10past and 50past

Tue Sep 11, 2018 9:18 pm

Be aware also that cron runs with its own somewhat cut down environment. All file paths (e.g. for your saved pictures) should be specified explicitly (e.g. /home/pi/images/snap1.jpg).

User avatar
Gavinmc42
Posts: 2122
Joined: Wed Aug 28, 2013 3:31 am

Re: raspi taking photo on boot every day at 10past and 50past

Tue Sep 11, 2018 11:36 pm

You can do a sequential filename by writing the name of the image file into a file and then next time cron fires your script the script reads the fillename out of the file and increments it then writes it back.
Or if you have a network connection or RTC use a file name with the timestamp in it.

You don't need to use Python, Bash Script files can do all this too.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Return to “General programming discussion”