diff --git a/relay.py b/relay.py index 7a37f86..3b38048 100644 --- a/relay.py +++ b/relay.py @@ -26,17 +26,16 @@ api_url = get_api_url() # Saves having to do the if-check every call. def main(): try: + s = requests.Session() while True: - # Make sure the U.R.L. is valid. - s = requests.Session() r = s.get(api_url, timeout=5) # print(r.status_code) # For testing. data = r.json() - # print(data) # For testing. + # print(f"{datetime.datetime.now()} -> {data}") # For testing. the_reading = data.get("reading") # print(the_reading) # For testing. if (device_id == "gallery1"): - if (the_reading > 38): + if (the_reading > 39): # print(f"[INFO: FACTORY1] Light is on -- {the_reading}.") GPIO.output(relay_pin, GPIO.HIGH) else: @@ -49,6 +48,7 @@ def main(): else: # print(f"[INFO: FACTORY2] Light is off -- {the_reading}.") GPIO.output(relay_pin, GPIO.LOW) + time.sleep(0.3) except KeyboardInterrupt: print("[INFO] KEYBOARD INTERRUPT: quitting program.") except requests.exceptions.ConnectionError: