Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import smtplib, sys, picamera, time
- from email.mime.image import MIMEImage
- from email.mime.multipart import MIMEMultipart
- from email.mime.text import MIMEText
- from email.header import Header
- from gpiozero import MotionSensor
- from pushbullet import PushBullet
- def foto(foto_pfad):
- camera = picamera.PiCamera()
- camera.capture(foto_pfad(640, 480))
- camera.close()
- def mail(foto_pfad):
- frm = 'my email address'
- to = 'my email address'
- smtpHost = 'my post exit server address'
- smtpPort = 587
- smtpUser = 'my email user name'
- smtpPassword = 'ma email password'
- subj = 'von RPI 3'
- msg = 'Foto von RPI 3'
- mime = MIMEMultipart()
- mime['From'] = frm
- mime['To'] = to
- mime ['Subject'] = Header(subj, 'utf-8')
- mime.attach(MIMEText(msg, 'plain', 'utf-8'))
- with open (foto_pfad, 'rb') as f:
- img = MIMEImage(f.read())
- mime.attach(img)
- smtp = smtplib.SMTP(smtpHost, smtpPort)
- smtp.login(smtpUser, smtpPassword)
- smtp.sendmail(frm, to, mime.as_string())
- smtp.quit()
- def mes():
- api_key = "my api key"
- phone_number = "my cellphone number"
- pb = PushBullet(api_key)
- device = pb.devices[0]
- device = pb.push_sms(device, phone_number,'Foto von RPI 3')
- count = 0
- def printit():
- global count
- count +=1
- t = time.strftime('%d.%m.%Y %H:%M:%S')
- print'PIR3 am', t, 'zum %d.Mal ausgeloest' % count
- while True:
- def on_motion():
- pfad = '/home/pi/bild1.jpg'
- foto(pfad)
- mail(pfad)
- mes()
- printit()
- if count %3 == 0:
- time.sleep(1800)
- print 'im Schlafmodus'
- pir = MotionSensor(11)
- pir.when_motion = on_motion
- time.sleep(10)
- sys.exit()
Add Comment
Please, Sign In to add comment