Guest User

Untitled

a guest
Dec 27th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #!/usr/bin/python3
  2. #-*-coding: utf-8-*-
  3. import sys, time, smtplib, picamera
  4. import RPi.GPIO as gpio
  5.  
  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(gpi.BOARD)
  12. gpio.setup(23, gpio.IN)
  13.  
  14. count = 0
  15. def mein_callback(pin):   
  16. count += 1   
  17. print('PIR 3 zum', str(count)+'. Mal aktiviert')
  18.  
  19.   frm = 'meine e-mail Adresse'   
  20. to = 'meine e-mail Adresse'   
  21. smtpHost = 'smtpauth.bluewin.ch'   
  22. smtpPort = 587   
  23. smtpUser = 'mein user Name'   
  24. smtpPassword = 'mein Passwort' 
  25. #T = time.strftime('%Y_%m_%d-%H:%M:%S)
  26. subj = 'von Raspberry3'   
  27. msg = 'Meldung von PIR3'           
  28. fn = 'foto1.jpg'       
  29. try:
  30. camera = picamera.PiCamera()       
  31. camera.capture(fn, resize=(640, 480))       
  32. camera.close()   
  33. except: 
  34. print('Camera Fehler')
  35.  
  36. mime = MIMEMultipart()   
  37. mime['From'] = frm   
  38. mime['To'] = to   
  39. mime['Subject'] = Header(subj, 'utf-8')   
  40. mime.attach(MIMEText(msg, 'plain', 'utf-8'))   
  41. f = open(fn, 'rb')   
  42. img = MIMEImage(f.read())    
  43. f.close()   
  44. mime.attach(img)
  45.  
  46.   smtp = smtplib.SMTP(smtpHost, smtpPort)   
  47. smtp.login(smtpUser, smtpPassword)   
  48. smtp.sendmail(frm, to, mime.as_string())   
  49. smtp.quit()   
  50. time.sleep(60)
  51.  
  52.   if count % 3 == 0:       
  53. print('Schlafmodus')       
  54. time.sleep(1800)
  55. try:   
  56. gpio.add_event_detect(23, gpio.RISING, callback = mein_callback)   
  57. while True:       
  58. time.sleep(0.5)
  59. except KexboardInterrupt:
  60. gpio.cleanup()
  61. print('ENDE PROGRAMM')
Add Comment
Please, Sign In to add comment