Advertisement
Guest User

Untitled

a guest
May 8th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. #!/usr/bin/python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. import sys, time, smtplib, picamera
  5. import RPi.GPIO as gpio
  6. from email.mime.image import MIMEImage
  7. from email.mime.multipart import MIMEMultipart
  8. from email.mime.text import MIMEText
  9. from email.header import Header
  10.  
  11. gpio.setmode(gpio.BOARD)
  12. gpio.setup(23, gpio.IN)
  13.  
  14. MAX_COUNT = 3
  15. PIR_DELAY = 10
  16. PIR_IGNORE_TIME = 60
  17.  
  18. def mein_callback(pin):
  19. global current_count
  20. current_count += 1
  21. if DEBUG:
  22. print('DEBUG: PIR IRQ um %s zum %sten mal' % (time.strftime('%d.%m.%Y %H:%M:%S'), current_count))
  23. gpio.add_event_detect(23, gpio.RISING, callback = mein_callback)
  24.  
  25. if DEBUG:
  26. print('DEBUG: PIR2 wartet auf IQR')
  27. try:
  28. while True:
  29. if current_count > last_count and last_count < MAX_COUNT and time.time() > (last_time + PIR_DELAY):
  30. frm = 'meine E-Mail Adresse'
  31. to = 'meine E-Mail Adresse'
  32. smtpHost = 'smtpauth.bluewin.ch'
  33. smtpPort = 587
  34. smtpUser = 'mein Name'
  35. smtpPassword = 'mein Passwort'
  36. subj = 'von Raspberry2'
  37. msg = 'Meldung von PIR2'
  38. fn = 'foto1.jpg'
  39.  
  40. camera = picamer.PiCamera()
  41. camera.capture(fn, resize=(640, 480))
  42. camera.close()
  43.  
  44. mime = MIMEMultipart()
  45. mime['From'] = frm
  46. mime['To'] = to
  47. mime['Subject'] = Header(subf, 'utf-8')
  48. mime.attach(msg, 'plain', 'utf-8'))
  49.  
  50. f = open(fn, 'rb')
  51. img = MIMEImage(f.read())
  52. f.close()
  53.  
  54. print('PIR 2 wurde %s mal ausgeloest' % current_count)
  55. last_count = current_count
  56.  
  57. if last count >= MAX_COUNT:
  58. if DEBUG:
  59. print("DEBUG: Beginne Ruhezustand fuer %s sekunden" % PIR_IGNORE_TIME)
  60. time.sleep(PIR_IGNORE_TIME)
  61. if DEBUG:
  62. print("DEBUG: Ende Ruhezustand, es wurden %s PIR IRQs gegistriert" % (current_count - last_count))
  63. last_count = 0
  64. current_count = 0
  65. time.sleep(5)
  66. except KeyboardInterrupt:
  67. gpio.cleanup()
  68. print('Ende PIR_V1.py')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement