Advertisement
Guest User

Untitled

a guest
May 8th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1.  
  2. import RPi.GPIO as GPIO
  3. import time
  4. import smtplib, ssl
  5.  
  6. port = 465
  7.  
  8. password = 'trustthyworthy4now'
  9.  
  10. context = ssl.create_default_context()
  11.  
  12. GPIO.setmode(GPIO.BCM)
  13.  
  14. GPIO.setup(23, GPIO.IN)
  15.  
  16. with smtplib.SMTP_SSL("smtp.gmail.com", port) as server:
  17.     server.login("rhubenov.development@gmail.com", password)
  18.     try:
  19.         time.sleep(2)
  20.         while True:
  21.             if GPIO.input(23):
  22.                 print("Motion detected")
  23.                 server.sendmail('rhubenov.development@gmail.com', 'rrhubenov@gmail.com', 'It works!')
  24.                 time.sleep(5)
  25.  
  26.             time.sleep(0.1)
  27.     except:
  28.         GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement