Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- #-*-coding: utf-8-*-
- import sys, time, smtplib, picamera
- import RPi.GPIO as gpio
- from email.mime.image import MIMEImage
- from email.mime.multipart import MIMEMultipart
- from email.mime.text import MIMEText
- from email.header import Header
- gpio.setmode(gpi.BOARD)
- gpio.setup(23, gpio.IN)
- count = 0
- def mein_callback(pin):
- count += 1
- print('PIR 3 zum', str(count)+'. Mal aktiviert')
- frm = 'meine e-mail Adresse'
- to = 'meine e-mail Adresse'
- smtpHost = 'smtpauth.bluewin.ch'
- smtpPort = 587
- smtpUser = 'mein user Name'
- smtpPassword = 'mein Passwort'
- #T = time.strftime('%Y_%m_%d-%H:%M:%S)
- subj = 'von Raspberry3'
- msg = 'Meldung von PIR3'
- fn = 'foto1.jpg'
- try:
- camera = picamera.PiCamera()
- camera.capture(fn, resize=(640, 480))
- camera.close()
- except:
- print('Camera Fehler')
- mime = MIMEMultipart()
- mime['From'] = frm
- mime['To'] = to
- mime['Subject'] = Header(subj, 'utf-8')
- mime.attach(MIMEText(msg, 'plain', 'utf-8'))
- f = open(fn, 'rb')
- img = MIMEImage(f.read())
- f.close()
- mime.attach(img)
- smtp = smtplib.SMTP(smtpHost, smtpPort)
- smtp.login(smtpUser, smtpPassword)
- smtp.sendmail(frm, to, mime.as_string())
- smtp.quit()
- time.sleep(60)
- if count % 3 == 0:
- print('Schlafmodus')
- time.sleep(1800)
- try:
- gpio.add_event_detect(23, gpio.RISING, callback = mein_callback)
- while True:
- time.sleep(0.5)
- except KexboardInterrupt:
- gpio.cleanup()
- print('ENDE PROGRAMM')
Add Comment
Please, Sign In to add comment