here is the code
import RPi.GPIO as GPIO
import time
import smtplib
import cred
try:
need_clean = False
GATE1 = MSG1 = '\nPool Gate1 was '
GATE2 = MSG2 = '\nPool Gate2 was '
GATE1_MSG = {True:'open', False:'closed'}
GATE2_MSG = {True:'open', False:'closed'}
print('Setting up SMS...')
def send_msg(opened:bool):
server = smtplib.SMTP( "smtp.mail.att.net", 587 )
server.starttls()
server.login( cred.FROM, cred.PASS )
str_print =''.join([MSG1, GATE1_MSG[opened], ' at ',
time.strftime('%I:%M:%S %p')])
print(str_print)
server.sendmail(cred.FROM, cred.TO, str_print)
server.quit()
print('Setting up hardware...')
GATE1 = 12
GATE2 = 13
GPIO.setmode(GPIO.BOARD)
GPIO.setup(GATE1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(GATE2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
next_state = True
need_clean = False
print('Ready!')
while True:
if GPIO.input(GATE1) == next_state:
send_msg(next_state)
next_state = not next_state
time.sleep(0.3)
while True:
if GPIO.input(GATE2) == next_state:
send_msg(next_state)
next_state = not next_state
time.sleep(0.3)
Code: Select all
except KeyboardInterrupt:
GPIO.cleanup()
need_clean = False
if need_clean:
GPIO.cleanup()
print('\nEnd!')