Reputation: 1
Have been searching for days and didn't find an answer or it didn't work for me.
I've built home alarm system with Raspberry Pi and PIR sensor. The alarm system consists of control.py and alarm.py scripts. The control.py is simple flask webpage for controlling alarm detection. The alarm.py is basicaly a while loop that checks if the sensor has been trigered.
I'm starting alarm.py with Popen from control.py. Is there a way to modify a variable in alarm.py from control.py (so that the while loop breaks and program exits)?
Line of code in control.py that starts a detection program:
detection = subprocess.Popen(['python', 'alarm.py'], shell=False)
And the loop in alarm.py:
while True:
CurrentState=GPIO.input(GPIO_PIR)
if CurrentState==1 and PreviousState==0:
print "Motion detected!"
PreviousState=1
elif CurrentState==1 and PreviousState==1:
print "Motion detected!"
elif CurrentState==0 and PreviousState==1:
PreviousState=0
time.sleep(0.1)
GPIO.cleanup()
Upvotes: 0
Views: 80
Reputation: 208475
Since you are starting alarm.py as a separate process, there is no shared variable space for directly setting any variable from control.py that alarm.py can access.
You have a few options here:
Upvotes: 1