compuguru
Posts: 7
Joined: Thu Sep 10, 2015 3:53 am

Cron job help! time.sleep not working.

Thu Sep 10, 2015 4:06 am

Hey guys, i have a raspberry pi that i am trying to automate my aquarium with, i have most of it figured out but am having some trouble getting my water pump to run for 5 seconds a day, this pump is used to dose chems/water treatments in small doses.

anyway, i am trying to run a script using the crontab, i know crontab is triggering the script because it works fine when i only have 1 line of code in the script file.

I need the code to turn on GPIO 19, and then shut it off after 5 seconds.

Any help is appreciated, please see the code i am trying to use below, GPIO 19 does come on but has to be shut off manually, the last line of code never runs.

Note: I have tried time.sleep(5) < without the spaces :cry:

Code: Select all

#!/usr/bin/python

import time

echo "0" > /sys/class/gpio/gpio19/value

time.sleep( 5 )

echo "1" > /sys/class/gpio/gpio19/value

User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: Cron job help! time.sleep not working.

Thu Sep 10, 2015 12:26 pm

Why not use one of the GPIO Python modules?

Dave.
Apple say... Monkey do !!

scotty101
Posts: 3958
Joined: Fri Jun 08, 2012 6:03 pm

Re: Cron job help! time.sleep not working.

Thu Sep 10, 2015 12:41 pm

Code: Select all

echo "0" > /sys/class/gpio/gpio19/value
This is not a valid python command. This is a bash script command.

Which do you want to write? Python or Bash?
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

compuguru
Posts: 7
Joined: Thu Sep 10, 2015 3:53 am

Re: Cron job help! time.sleep not working.

Thu Sep 10, 2015 1:07 pm

Can bash and python work in tandem? If not I would like to use bash, unless it is not capable of a delay.

User avatar
Douglas6
Posts: 4874
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Cron job help! time.sleep not working.

Thu Sep 10, 2015 1:32 pm

compuguru wrote:Can bash and python work in tandem?
Not like that.

Code: Select all

sleep 5
in bash.

compuguru
Posts: 7
Joined: Thu Sep 10, 2015 3:53 am

Re: Cron job help! time.sleep not working.

Thu Sep 10, 2015 2:27 pm

So, remove the brackets and the number will trigger a delay for x seconds?

I'll give this a shot when I get home!

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: Cron job help! time.sleep not working.

Thu Sep 10, 2015 5:03 pm

If it's meant to be bash, it's probably also worth changing the shebang at the start of your script. It's currently set for python.

Given your description of the problem, this probably won't alter anything (as it sounds like the script is being interpreted as bash already) but it'll remove some confusion for other people!
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
Douglas6
Posts: 4874
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Cron job help! time.sleep not working.

Thu Sep 10, 2015 5:09 pm

And remove

Code: Select all

import time
It's helpful to test your cron scripts from a command line first.

compuguru
Posts: 7
Joined: Thu Sep 10, 2015 3:53 am

Re: Cron job help! time.sleep not working.

Thu Sep 10, 2015 6:04 pm

Thank you for the suggestions!

Return to “Python”