From d4eedda8117c22b9aa22f77361c0db5570f98007 Mon Sep 17 00:00:00 2001 From: Keriz Date: Tue, 3 Oct 2017 10:36:08 +0200 Subject: [PATCH] fix for the message spamming might need to remove an import, and have to check if there if the state sent to the API is the good one (right now it looks like its always closed) --- main.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index c1008e1..12f21dc 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,7 @@ start_time = None final_url = "https://racks.octanis.org/api/v1/racks/1/geography/KEY" state = 0 +start_state = 0 channel = port.PA10 gpio.init() gpio.setcfg(channel, gpio.INPUT) @@ -24,8 +25,9 @@ state = 0 if(prevstate != state): print("change detected") - if (start_time == None): + if (start_time is None): start_time = time.time() + start_state = state File.write(strftime("%a, %d %b %Y %H:%M:%S", gmtime()) + " MED 3 2215 is " + ("opened." if state == 1 else "closed.") + "\n") else: @@ -33,8 +35,9 @@ elapsed_time = time.time() - start_time if (elapsed_time >= 60): start_time = None - payload = {'accessibleToPublic': state} - response = requests.post(final_url, data=payload) + if (start_state == state): + payload = {'accessibleToPublic': state} + response = requests.post(final_url, data=payload) except KeyboardInterrupt: print ("Goodbye.")