-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalarm.py
executable file
·43 lines (32 loc) · 1.25 KB
/
alarm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import RPi.GPIO as GPIO #pylint: disable=import-error
import time
import smtplib
#https://support.google.com/mail/answer/185833?hl=en how to create app specific password for Gmail
class Alarm:
def __init__(
self, pin = 18,
sender_email="[email protected]",
password="YOURREALORGENERATEDPASSWORD",
receiver_email="[email protected]"):
self.pin = pin
self.sender_email = sender_email
self.password = password
self.receiver_email = receiver_email
GPIO.setup(self.pin,GPIO.OUT)
def beep(self):
GPIO.output(self.pin, GPIO.HIGH)
# make sure time.sleep() is lower than the sensor_reading_delay in app.py
time.sleep(0.5)
GPIO.output(self.pin, GPIO.LOW)
def cleanup(self):
GPIO.cleanup()
#For this example we're using Python to connect to our Gmail account and send an email.
def send_email(self):
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.login(self.sender_email, self.password)
server.sendmail(
self.sender_email,
self.receiver_email,
"!!! FIRE ALARM !!!")
server.quit()
print('EMAIL SENT')