-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbutton.py
More file actions
52 lines (51 loc) · 1.83 KB
/
button.py
File metadata and controls
52 lines (51 loc) · 1.83 KB
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
44
45
46
47
48
49
50
51
52
import os
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(4,GPIO.IN)
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.Utils import COMMASPACE, formatdate
from email import Encoders
import smtplib
prev_input = 0
#data = time.strftime("%H:%M:%S")
#data_s = time.strftime("%c")
#data_f = time.strftime("%c")
while True:
input = GPIO.input(4)
if ((prev_input) != input):
if (input==0):
#create email
message = """PREZENTA TENSIUNE - PARC ULMU """ + time.strftime("%c")
msg = MIMEText(message)
msg['subject'] = 'Alerta HUPA ULMU - Stop'
msg['from'] = 'xx@xxx.com'
msg['to'] = 'xx@xxx.com'
# send mail
#s = smtplib.SMTP('smtp.mailgun.org:25')
s = smtplib.SMTP('smtp.mailgun.org',587)
s.login('user_login@domeniu.ro' , 'parola')
s.sendmail(msg['From'], msg['To'], msg.as_string())
s.quit
print ("Alerta STOP")
time.sleep(5)
else:
#create email
message = """LIPSA TENSIUNE - PARC ULMU """ + time.strftime("%c")
msg = MIMEText(message)
msg['subject'] = 'Alerta HUPA ULMU - Start'
msg['from'] = 'xx@xxx.com'
msg['to'] = 'xx@xxx.com'
# send mail
#s = smtplib.SMTP('smtp.mailgun.org:25')
s = smtplib.SMTP('smtp.mailgun.org',587)
s.login('user_login@domeniu.ro' , 'parola')
s.sendmail(msg['From'], msg['To'], msg.as_string())
s.quit
print ("Alerta START")
time.sleep(5)
prev_input = input
#slight pause to debounce
time.sleep(0.05)