I'm working on a project which will use a PIR motion sensor to take a photo of the room, also triggered by the PIR sensor. I'm using the PIR sensor for something else at the same time, so I'd rather make further use of the sensor, rather than use something like motionEye.
I'm new to Linux, but not to Python. At the moment, my code is:
import RPi.GPIO as GPIO import time import webbrowser as web from subprocess import call GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(11, GPIO.IN) #Open local web page in default browser web.open_new_tab(/home/pi/Desktop/webpage_cal_weather.html') while True: i = GPIO.input(11) #Read output from PIR sensor if i==0: call(['usr/bin/vcgencmd', 'display_power', '0']) #Turn monitor off time.sleep(5) elif i==1: id = str(time.time()) filename = "/home/pi/camera/"+id"".jpg" call(['usr/bin/vcgencmd', 'display_power', '0']) #Turn monitor on call(['usr/bin/raspistill', '-o', filename]) #Take a photo
Is there a better way to implement it so that the filenames don't duplicate?