Advertisement
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(gpio.BOARD)
- gpio.setup(23, gpio.IN)
- MAX_COUNT = 3
- PIR_DELAY = 10
- PIR_IGNORE_TIME = 60
- def mein_callback(pin):
- global current_count
- current_count += 1
- if DEBUG:
- print('DEBUG: PIR IRQ um %s zum %sten mal' % (time.strftime('%d.%m.%Y %H:%M:%S'), current_count))
- gpio.add_event_detect(23, gpio.RISING, callback = mein_callback)
- if DEBUG:
- print('DEBUG: PIR2 wartet auf IQR')
- try:
- while True:
- if current_count > last_count and last_count < MAX_COUNT and time.time() > (last_time + PIR_DELAY):
- frm = 'meine E-Mail Adresse'
- to = 'meine E-Mail Adresse'
- smtpHost = 'smtpauth.bluewin.ch'
- smtpPort = 587
- smtpUser = 'mein Name'
- smtpPassword = 'mein Passwort'
- subj = 'von Raspberry2'
- msg = 'Meldung von PIR2'
- fn = 'foto1.jpg'
- camera = picamer.PiCamera()
- camera.capture(fn, resize=(640, 480))
- camera.close()
- mime = MIMEMultipart()
- mime['From'] = frm
- mime['To'] = to
- mime['Subject'] = Header(subf, 'utf-8')
- mime.attach(msg, 'plain', 'utf-8'))
- f = open(fn, 'rb')
- img = MIMEImage(f.read())
- f.close()
- print('PIR 2 wurde %s mal ausgeloest' % current_count)
- last_count = current_count
- if last count >= MAX_COUNT:
- if DEBUG:
- print("DEBUG: Beginne Ruhezustand fuer %s sekunden" % PIR_IGNORE_TIME)
- time.sleep(PIR_IGNORE_TIME)
- if DEBUG:
- print("DEBUG: Ende Ruhezustand, es wurden %s PIR IRQs gegistriert" % (current_count - last_count))
- last_count = 0
- current_count = 0
- time.sleep(5)
- except KeyboardInterrupt:
- gpio.cleanup()
- print('Ende PIR_V1.py')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement