doorlock

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 581849eeef5811ab88893c203f4c9f08129ee8a5
parent e58f868f21172ae2a7ea6855804493ec6c5659c2
Author: rbckman <rob@tarina.org>
Date:   Sun,  7 Nov 2021 10:38:09 +0200

initial commit?

Diffstat:
Mdoorlock.py | 42++++++++++++++++++++++++++++--------------
1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/doorlock.py b/doorlock.py @@ -10,7 +10,7 @@ import pickle #bygdis keypad dörrlås system keypass = '' -passcodes = ['2222', '0550'] +passcodes = [] rundir = os.path.dirname(__file__) if rundir != '': os.chdir(rundir) @@ -40,6 +40,7 @@ def save_passcodes(passcodes): def load_passcodes(): global folder passcodes = pickle.load(open(folder+'/.doorlock.p', 'rb')) + return passcodes def check_if_open(): if GPIO.input(14): @@ -60,16 +61,35 @@ def is_webz_on(): def getcodes(): global apikey url = 'https://bygdis.fi/dorrkoderapi?apikey='+apikey - resp = requests.get(url=url) - data = resp.json() + try: + resp = requests.get(url=url) + data = resp.json() + save_passcodes(data) + except: + print('cant access bygdis.fi') + data = load_passcodes() return data def keylogger(code): global apikey print('logging key ' + str(code)) url = 'https://bygdis.fi/dorrkoderapi?apikey='+apikey+'&logger=' + str(code) - resp = requests.get(url=url) - print(resp) + try: + resp = requests.get(url=url) + print(resp) + except: + print('cant access bygdis.fi') + return + +def doordebug(): + global apikey, open_door + print('sending debug info to bygdis.fi api') + url = 'https://bygdis.fi/dorrkoderapi?apikey='+apikey+'&doorstate='+str(open_door) + try: + resp = requests.get(url=url) + print(resp) + except: + print('cant send debug info to bygdis.fi') return def keybeep(): @@ -78,14 +98,8 @@ def keybeep(): GPIO.output(21,GPIO.LOW) def failbeep(): - p = 0 - while p < 100: - GPIO.output(20,GPIO.HIGH) - GPIO.output(21,GPIO.HIGH) - GPIO.output(21,GPIO.LOW) - GPIO.output(20,GPIO.LOW) - time.sleep(0.05) - p += 1 + successbeep() + successbeep() def successbeep(): GPIO.output(21,GPIO.HIGH) @@ -148,7 +162,7 @@ while 1: get_code_time = time.time() if is_webz_on(): passcodes = getcodes() - save_passcodes(passcodes) + doordebug() else: passcodes = load_passcodes() if open_door == True: