-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaster_monitor.py
More file actions
31 lines (26 loc) · 811 Bytes
/
master_monitor.py
File metadata and controls
31 lines (26 loc) · 811 Bytes
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, os, RPi.GPIO as GPIO, requests
DATA_DIR = "/home/pi/allsky_guard"
WIND_LIMIT = 15.0
RAIN_PIN = 22
PARK_PIN = 18
CLOSE_RELAY = 27
GPIO.setmode(GPIO.BCM)
GPIO.setup(CLOSE_RELAY, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup([RAIN_PIN, PARK_PIN], GPIO.IN, pull_up_down=GPIO.PUD_UP)
def emergency_shutdown():
try: requests.get("http://192.168.1.50/api/park", timeout=2)
except: pass
for _ in range(45):
if GPIO.input(PARK_PIN) == GPIO.LOW:
GPIO.output(CLOSE_RELAY, GPIO.LOW)
time.sleep(1.5)
GPIO.output(CLOSE_RELAY, GPIO.HIGH)
break
time.sleep(1)
def run_monitor():
while True:
if GPIO.input(RAIN_PIN) == GPIO.LOW:
emergency_shutdown()
time.sleep(5)
if __name__ == "__main__":
run_monitor()