Brandon_K
Posts: 2
Joined: Wed Nov 12, 2014 4:34 am

Using a sleep function with WiringPi / GPIO & other ?'s

Wed Nov 12, 2014 5:46 am

I'm building a few RPi's to have switch inputs which then send a push notification via Pushover to our team's cell phones.

The very basic code I have so far;

Code: Select all


#! /bin/bash
gpio mode 7 down

app="Panic Button Town"
message="KITCHEN"
title="PANIC BUTTON"
url=
url_title=
priority=
device=
sound= userkey=*mykeyhere*
apikey=*myAPIkeyhere*

while true
        do

        gpio wfi 7 rising
curl https://api.pushover.net/1/messages.json -F token=$apikey -F user=$userkey -F message="Kitchen" -F title=$title -F sound=alien -F priority=1

done
The code works for all intents and purposes. But, I need to add a time delay before it will allow sending the http request to Pushover again. The primary reasons for this are button debounce and to stop the alerts from being constantly retriggered as these are being switched by locking E-stop buttons.

I've attempted my limited knowledge, lots of Google, import time, etc etc and I can't get any combination to work. I would like to put a 60 second delay on it before it would resend the http.

Help?

ground_
Posts: 17
Joined: Tue Oct 14, 2014 6:13 am

Re: Using a sleep function with WiringPi / GPIO & other ?'s

Wed Nov 12, 2014 9:58 pm

although i am nt compeltely sure what you want, this is maybe the solution:

Code: Select all

#! /bin/bash
import time
gpio mode 7 down

app="Panic Button Town"
message="KITCHEN"
title="PANIC BUTTON"
url=
url_title=
priority=
device=
sound= userkey=*mykeyhere*
apikey=*myAPIkeyhere*

while true
        do

        gpio wfi 7 rising
curl https://api.pushover.net/1/messages.json -F token=$apikey -F user=$userkey -F message="Kitchen" -F title=$title -F sound=alien -F priority=1
        time.sleep(60)
        done
it littlerally let the script sleep for 60 seconds before it continous.

Brandon_K
Posts: 2
Joined: Wed Nov 12, 2014 4:34 am

Re: Using a sleep function with WiringPi / GPIO & other ?'s

Thu Nov 13, 2014 7:08 am

I don't feel so bad anymore, as that is exactly what I was doing. When I have those 2 additional lines in there "Import time" "time.sleep(60)", this is what I get when I run it as ./panic

Code: Select all

pi@raspberrypi ~/panic $ ./panic
./panic: line 2: import: command not found
./panic: line 20: syntax error near unexpected token `60'
./panic: line 20: `     time.sleep(60)'
If I run it as sudo python panic, I get this as a result;

Code: Select all

pi@raspberrypi ~/panic $ sudo python panic
  File "panic", line 3
    gpio mode 7 down
            ^
SyntaxError: invalid syntax
I'm not sure why it's coming back as invalid syntax, as when it's run as ./panic or ./panic& , the script runs fine (without the time issues, at least)

User avatar
rpdom
Posts: 17174
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Using a sleep function with WiringPi / GPIO & other ?'s

Thu Nov 13, 2014 7:17 am

There has been some confusion because your script is written in Bash and not Python.
Remove the "import" line and change "time.sleep(60)" to "sleep 60".

Then run the code with "./panic".

Return to “Python”