-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
32 lines (24 loc) · 1.07 KB
/
main.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
import time
import os
import RPi.GPIO as GPIO
from alt_msg import AltMessage
from send_email_notification import send_email_message
from send_sms_notification import send_sms_message
pin = int(os.environ['WATER_PIN']) # Setting `pin` for ease-of-use below - assumes value exists in the runtimes environment (`export`, .env file, etc.)
os.environ['on_value'] = "0" # Set this for YOUR setup!!
def pin_activated(activated_pin):
incoming_value = GPIO.input(activated_pin)
if os.environ['on_value'] == incoming_value:
print(f"pin_activated Log: Activated pin = {activated_pin} - Value = {incoming_value}")
if __name__ == "__main__":
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(pin, GPIO.IN)
GPIO.add_event_detect(pin, GPIO.BOTH, bouncetime=300)
GPIO.add_event_callback(pin, pin_activated)
GPIO.add_event_callback(pin, AltMessage())
GPIO.add_event_callback(pin, send_email_message)
GPIO.add_event_callback(pin, send_sms_message)
print(f"Current value of pin: {GPIO.input(pin)}\n")
while True:
time.sleep(60)