Hi
I wan't to use the RPI as security camera. When detecting a motion on PIR module it should take a picture/video and send it through email.
I attached a RPICamerav3 on a RPI5 with 4gbram and I'm using a SR501 for motion detection.
I installed and configured postfix to use gmail as outgoing smtp through sasl.
I wrote a simple python script to make it works but when I activate email sending it triggers false positives on the PIR.
If I deactivate the mail-sending part it works fine and capture what I request but once I activate the email sending it trigger false positive (I tried to put a time.sleep(20) after each detection and it solve the problem but I makes 'blind' moments
here below the script (I changed the emails for anonymization) :
I wan't to use the RPI as security camera. When detecting a motion on PIR module it should take a picture/video and send it through email.
I attached a RPICamerav3 on a RPI5 with 4gbram and I'm using a SR501 for motion detection.
I installed and configured postfix to use gmail as outgoing smtp through sasl.
I wrote a simple python script to make it works but when I activate email sending it triggers false positives on the PIR.
If I deactivate the mail-sending part it works fine and capture what I request but once I activate the email sending it trigger false positive (I tried to put a time.sleep(20) after each detection and it solve the problem but I makes 'blind' moments
here below the script (I changed the emails for anonymization) :
Code:
from datetime import datetimeimport osimport RPi.GPIO as GPIOimport timeimport smtplibfrom email.mime.multipart import MIMEMultipartfrom email.mime.text import MIMETextfrom email.mime.application import MIMEApplicationfrom picamzero import Cameragpiopin=13GPIO.setmode(GPIO.BOARD)GPIO.setup(gpiopin,GPIO.IN)cam = Camera()def sendemail(filename): sender_email = "xxx" recipient_email = "xxx" message = MIMEMultipart() message['Subject'] = "Detection " message['From'] = sender_email message['To'] = recipient_email body_part = MIMEText("Detection ") message.attach(body_part) with open("/home/images/"+filename,'rb') as file: message.attach(MIMEApplication(file.read(), Name=filename)) with smtplib.SMTP("127.0.0.1", 25) as server: server.sendmail(sender_email, recipient_email, message.as_string())def sendsinglepicture(nbr): print(nbr) for i in range(nbr): print(i) filename="image"+datetime.now().strftime("%Y-%m-%d--%H-%M-%S") cam.take_photo("/home/images/"+filename+".jpg") sendemail(filename+".jpg")def sendsequence(nbr): print(nbr) filename="image"+datetime.now().strftime("%Y-%m-%d--%H-%M-%S") cam.capture_sequence("/home/images/"+filename+".jpg", num_images=nbr, interval=.25) print("picture taken : "+filename) if nbr<10: for j in range(min(9,nbr)): sendemail(filename+"-"+str(j+1)+".jpg") else: for j in range(min(9,nbr)): sendemail(filename+"-0"+str(j+1)+".jpg") for j in range(min(9,nbr), nbr): sendemail(filename+"-"+str(j+1)+".jpg") def sendvideo(temps): print(temps) filename="image"+datetime.now().strftime("%Y-%m-%d--%H-%M-%S") cam.record_video("/home/images/"+filename+".mp4", duration=temps) print("picture taken : "+f
Statistics: Posted by prmvh — Sat Nov 02, 2024 6:09 pm