Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import RPi.GPIO as GPIO
- import time
- import smtplib
- from email.mime.image import MIMEImage
- from email.mime.multipart import MIMEMultipart
- from requests import get
- from email.mime.text import MIMEText
- import os
- import subprocess
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
- ip = get('https://api.ipify.org').text
- def send_mail():
- subject="FIRE!!!!!!"
- fstation="[email protected]"
- fs_pass="firestation123"
- user="[email protected]"
- msg = MIMEMultipart()
- msg['Subject'] = subject
- msg['From'] = fstation
- msg['To'] = user
- msg.preamble = subject
- msg_txt = ("<html>"
- "<head></head>"
- "<body>"
- "<h1> theres a fire </h1>"
- "<p>%s</p>"
- "</body>"
- "</html>" % ip)
- msg.attach(MIMEText(msg_txt, 'html'))
- with open("test.jpg") as f:
- msg.attach(MIMEImage(f.read()))
- s = smtplib.SMTP('smtp.gmail.com',587)
- print ("connection stablished")
- s.starttls()
- s.ehlo_or_helo_if_needed()
- s.login(fstation,fs_pass)
- s.sendmail(fstation, user, msg.as_string())
- s.quit()
- def filewriting():
- with open('info.txt', 'a') as file:
- file.write(time.strftime("%H:%M:%S")+' on '+time.strftime("%d/%m/%Y")+' ;')
- def my_callback (pin):
- print('Theres a fire with ip: {}'.format(ip))
- os.system("fswebcam -r 640x480 --jpeg 85 -D 1 test.jpg")
- send_mail()
- filewriting()
- os.system("rm -f -r {damn-fire.jpg}")
- GPIO.add_event_detect(27, GPIO.RISING, callback=my_callback, bouncetime = 500)
- while True :
- time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment