diff --git a/app.py b/app.py index f17f146..fbbcdaa 100644 --- a/app.py +++ b/app.py @@ -245,4 +245,4 @@ def deactivate_token(token): if __name__ == '__main__': - app.run() + app.run(host='0.0.0.0') diff --git a/door_handle.py b/door_handle.py index 09f41d4..36a6b37 100644 --- a/door_handle.py +++ b/door_handle.py @@ -1,14 +1,13 @@ import paho.mqtt.client as mqtt -import re class DoorHandle: - def __init__(self, host, port=1883): + def __init__(self, host, port=1883, token_file='/etc/door_tokens'): self.state = None self.encoder_position = None + self.last_invalid = {} - self.token_file = 'door_tokens' - self.nfc_logfile = 'nfc.log' + self.token_file = token_file self.mqtt_client = mqtt.Client() self.mqtt_client.on_connect = self.on_connect @@ -33,6 +32,9 @@ class DoorHandle: self.state = msg.payload.decode() elif msg.topic == 'door/position/value': self.encoder_position = int(msg.payload) + elif msg.topic == 'token/last_invalid': + timestamp, token = msg.payload.split(';') + self.last_invalid = {'token': token, 'timestamp': timestamp} def get_tokens(self): tokens = {} @@ -68,11 +70,5 @@ class DoorHandle: f.write(output) - def get_most_recent_token(self): - # read last invalid token from logfile - with open(self.nfc_logfile) as f: - nfc_log = f.read() - match = re.search(r"(?P\d{4}-\d{2}-\d{2}) (?P