+ 1

help

I am using a raspberry pi and I have this code set to blink lights for 10 seconds. I am using a library called bottle from bottlepy.org to allow me to run a specific function tied to a web url. Ex. if i say @route('/bug') def bug(): print("Hello World") then going to the ip address of the pi followed by :1234/bug will run just that function. Here is my code followed by my issue. # Import Libraries import RPi.GPIO as GPIO import time from bottle import route, run #Setup GPIO Pins GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(17,GPIO.OUT) GPIO.setup(15,GPIO.OUT) #Set always on GPIO to Off GPIO.output(17,GPIO.LOW) timeout=time.time() + 10 print "Lets Start Blinking!!!!" @route('/blink') def blink(): GPIO.output(17,GPIO.HIGH) time.sleep(1) GPIO.output(17,GPIO.LOW) GPIO.output(15,GPIO.HIGH) time.sleep(1) GPIO.output(15,GPIO.LOW) while True: blink() if time.time()> timeout: break continue run(host='192.168.1.70' , port=1234) When I first run the program the lights blink for 10 seconds. Then I go to the url on my phone and click enter and it only blinks the lights once and does not blink for the full 10 seconds. Anyone have any idea whats wrong with my code?

6th Jun 2019, 1:04 AM
Bryan
3 Answers
0
You assigned "timeout" only once, in the initialization phase. You have to assign it inside blink() function; in this way it will be recalculated everytime you address your URL!
6th Jun 2019, 6:17 PM
Bilbo Baggins
Bilbo Baggins - avatar
0
That doesnt work. Every time the blink function repeats because of continue this resets the timer and it goes non stop. But you give me an idea. I will create a function within a function. The web url will call the function that sets the timer and then activates the while loop...maybe that will work
6th Jun 2019, 8:32 PM
Bryan
0
Maybe def call_blink(): timeout=time.time() + 10 while True: blink() If time.time()> timeout Break Continue
6th Jun 2019, 8:34 PM
Bryan