Guest User

Untitled

a guest
Apr 9th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. #!/usr/bin/python
  2. import smtplib, sys, picamera, time
  3. from email.mime.image import MIMEImage
  4. from email.mime.multipart import MIMEMultipart
  5. from email.mime.text import MIMEText
  6. from email.header import Header
  7. from gpiozero import MotionSensor
  8. from pushbullet import PushBullet
  9. def foto(foto_pfad):     
  10. camera = picamera.PiCamera()   
  11. camera.capture(foto_pfad(640, 480))   
  12. camera.close()
  13.  
  14. def mail(foto_pfad):
  15. frm = 'my email address'   
  16. to = 'my email address'   
  17. smtpHost = 'my post exit server address'   
  18. smtpPort =  587   
  19. smtpUser = 'my email user name'   
  20. smtpPassword = 'ma email password'   
  21. subj = 'von RPI 3'   
  22. msg = 'Foto von RPI 3'
  23.  
  24.     mime = MIMEMultipart()   
  25. mime['From'] = frm   
  26. mime['To'] = to   
  27. mime ['Subject'] = Header(subj, 'utf-8')   
  28. mime.attach(MIMEText(msg, 'plain', 'utf-8'))
  29.  
  30.     with open (foto_pfad, 'rb') as f:
  31. img = MIMEImage(f.read())
  32. mime.attach(img)   
  33. smtp = smtplib.SMTP(smtpHost, smtpPort)   
  34. smtp.login(smtpUser, smtpPassword)   
  35. smtp.sendmail(frm, to, mime.as_string())   
  36. smtp.quit()
  37. def mes():   
  38. api_key = "my api key"   
  39. phone_number = "my cellphone number"   
  40. pb = PushBullet(api_key)   
  41. device = pb.devices[0]   
  42. device = pb.push_sms(device, phone_number,'Foto von RPI 3')
  43.  
  44. count = 0
  45. def printit():   
  46. global count   
  47. count +=1   
  48. t = time.strftime('%d.%m.%Y %H:%M:%S')   
  49. print'PIR3 am', t, 'zum %d.Mal ausgeloest' % count
  50.  
  51. while True:
  52. def on_motion():   
  53. pfad = '/home/pi/bild1.jpg'
  54. foto(pfad)
  55. mail(pfad)
  56. mes()   
  57. printit()   
  58. if count %3 == 0:       
  59. time.sleep(1800)       
  60. print 'im Schlafmodus'
  61. pir = MotionSensor(11)
  62. pir.when_motion = on_motion
  63. time.sleep(10)
  64. sys.exit()
Add Comment
Please, Sign In to add comment