Compare commits
No commits in common. "f43cfcf131e1da5e67b67b1eb5c16a1590716d62" and "b7f3f57efd2f187a912916e39901ff7a4353543b" have entirely different histories.
f43cfcf131
...
b7f3f57efd
32
kdoorpi.py
32
kdoorpi.py
@ -29,12 +29,12 @@ class DoorController:
|
||||
api_longpoll,
|
||||
api_swipe,
|
||||
api_key,
|
||||
uid_salt):
|
||||
uid_hash):
|
||||
self.door = door
|
||||
self.api_allowed = api_allowed
|
||||
self.api_longpoll = api_longpoll
|
||||
self.api_swipe = api_swipe
|
||||
self.uid_salt = uid_salt
|
||||
self.uid_hash = uid_hash
|
||||
|
||||
self.uids = {}
|
||||
|
||||
@ -67,19 +67,20 @@ class DoorController:
|
||||
uids.add(token["token"]["uid_hash"].strip())
|
||||
self.uids = uids
|
||||
|
||||
def wiegand_callback(self, value):
|
||||
uid_hash = hash_uid(value, self.uid_salt)
|
||||
logging.debug(f"hash {uid_hash}")
|
||||
if uid_hash in self.uids:
|
||||
logging.info(f"Opening door for UID hash trail {uid_hash[-10:]}")
|
||||
def wiegand_callback(self, bits, value):
|
||||
uid_h = hash_uid(value, self.uid_hash)
|
||||
logging.debug("hash %s", uid_h)
|
||||
if uid_h in self.uids:
|
||||
logging.info("Opening door for UID hash trail %s", uid_h[-10:])
|
||||
self.wiegand.open_door()
|
||||
success = True
|
||||
else:
|
||||
logging.info(f"Access card not in allow list, hash trail {uid_hash[-10:]}")
|
||||
logging.info("Access card not in allow list, hash trail %s",
|
||||
uid_h[-10:])
|
||||
success = False
|
||||
data = {
|
||||
"uid": value,
|
||||
"uid_hash": uid_hash,
|
||||
"uid_hash": uid_h,
|
||||
"door": self.door,
|
||||
"timestamp": time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
|
||||
}
|
||||
@ -126,10 +127,9 @@ class DoorController:
|
||||
|
||||
if __name__ == "__main__":
|
||||
DoorController(
|
||||
door=os.environ["KDOORPI_DOOR"],
|
||||
api_allowed=os.environ["KDOORPI_API_ALLOWED"],
|
||||
api_longpoll=os.environ["KDOORPI_API_LONGPOLL"],
|
||||
api_swipe=os.environ["KDOORPI_API_SWIPE"],
|
||||
api_key=os.environ["KDOORPI_API_KEY"],
|
||||
uid_salt=os.environ["KDOORPI_UID_SALT"],
|
||||
)
|
||||
os.environ["KDOORPI_DOOR"],
|
||||
os.environ["KDOORPI_API_ALLOWED"],
|
||||
os.environ["KDOORPI_API_LONGPOLL"],
|
||||
os.environ["KDOORPI_API_SWIPE"],
|
||||
os.environ["KDOORPI_API_KEY"],
|
||||
os.environ["KDOORPI_UID_SALT"])
|
||||
|
26
wiegand.py
26
wiegand.py
@ -56,7 +56,7 @@ class Decoder:
|
||||
self._cb)
|
||||
self.button_cb_h = self.pi.callback(self.button_pin,
|
||||
pigpio.FALLING_EDGE,
|
||||
self.button_cb)
|
||||
self._cb)
|
||||
|
||||
def cut_empty(self, item):
|
||||
if item[0:8] == "00000000":
|
||||
@ -64,8 +64,7 @@ class Decoder:
|
||||
else:
|
||||
return item
|
||||
|
||||
@property
|
||||
def hex(self):
|
||||
def get_hex(self):
|
||||
try:
|
||||
items = self.items
|
||||
if len(self.items) == 26:
|
||||
@ -80,11 +79,12 @@ class Decoder:
|
||||
bits))).rstrip()
|
||||
|
||||
except ValueError:
|
||||
logging.error(f"Failed to convert binary to hex: {self.items}")
|
||||
logging.error("Failed to convert binary to hex: %s" % self.items)
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"Wiegand convert error (raw: {self.items}): {e}")
|
||||
logging.error("Wiegand convert error (raw: %s): %s" % (
|
||||
self.items, e))
|
||||
return False
|
||||
|
||||
def _cb(self, gpio_pin, level, tick):
|
||||
@ -99,7 +99,7 @@ class Decoder:
|
||||
if self.in_code:
|
||||
self.bits += 1
|
||||
else:
|
||||
logging.debug(f"Wiegand data transfer start")
|
||||
logging.debug("Wiegand data transfer start")
|
||||
self.bits = 1
|
||||
self.items = ""
|
||||
self.in_code = True
|
||||
@ -129,18 +129,20 @@ class Decoder:
|
||||
self.in_code = False
|
||||
|
||||
if self.bits >= 26:
|
||||
hex = self.hex
|
||||
hex = self.get_hex()
|
||||
if hex:
|
||||
self.callback(hex)
|
||||
self.callback(self.bits, hex)
|
||||
else:
|
||||
logging.error(f"Expected 26 bits, but got {self.bits:d}: {self.items}")
|
||||
logging.error("Expected 26 bits, but got %i: %s" %
|
||||
(self.bits, self.items))
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"Wiegand callback error: {e}")
|
||||
logging.error("Wiegand callback error: %s" % e)
|
||||
|
||||
def button_cb(self, gpio_pin, level, tick):
|
||||
print(f"button: gpio_pin:{gpio_pin}, level:{level}, tick:{tick}")
|
||||
self.open_door()
|
||||
print("button: gpio_pin:{}, level:{}, tick:{}".format(gpio_pin,
|
||||
level,
|
||||
tick))
|
||||
|
||||
def open_door(self):
|
||||
self.pi.write(self.door_pin, 1)
|
||||
|
Loading…
Reference in New Issue
Block a user