use MQTT to get last invalid token
This commit is contained in:
parent
28f95740af
commit
4d405c66d6
2
app.py
2
app.py
|
@ -245,4 +245,4 @@ def deactivate_token(token):
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
app.run(host='0.0.0.0')
|
||||
|
|
|
@ -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<date>\d{4}-\d{2}-\d{2}) (?P<time>\d{2}:\d{2}:\d{2}) Invalid token: (?P<token>[[:xdigit:]]{14})",
|
||||
nfc_log, re.REVERSE)
|
||||
return match
|
||||
return self.last_invalid
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
{% endwith %}
|
||||
{% if token is not none %}
|
||||
Letzter unregistrierter Token: {{ token['token'] }} <br>
|
||||
Gelesen am {{ token['date'] }} um {{ token['time'] }}
|
||||
Timestamp {{ token['timestamp'] }}
|
||||
|
||||
<div>
|
||||
<p>
|
||||
|
|
Loading…
Reference in New Issue
Block a user