mirror of
https://gitlab.com/fabinfra/fabaccess/fabfire_adapter.git
synced 2025-03-12 14:51:50 +01:00
fixed single
This commit is contained in:
parent
59210d1f34
commit
7bca060dab
@ -93,7 +93,7 @@ async def connect_with_fabfire_initial(host, port, uid):
|
||||
return auth, response.challenge
|
||||
else:
|
||||
logging.error(f"Auth failed: {response.failed.code}, additional info: {response.failed.additionalData}")
|
||||
return None
|
||||
return None, None
|
||||
|
||||
|
||||
async def connect_with_fabfire_step(auth, msg):
|
||||
@ -106,4 +106,4 @@ async def connect_with_fabfire_step(auth, msg):
|
||||
return response.successful.additionalData, response.successful.session # dont care, message, we are done
|
||||
else:
|
||||
logging.error(f"Auth failed: {response.failed.code}, additional info: {response.failed.additionalData}")
|
||||
return None
|
||||
return None, None
|
||||
|
2
schema
2
schema
@ -1 +1 @@
|
||||
Subproject commit 18ed9c2ae6a221f57d19e255165c7ebc4508e9af
|
||||
Subproject commit 19f20f5154f0eced6288ff56cac840025ee51da1
|
40
single.py
40
single.py
@ -1,33 +1,35 @@
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
import os
|
||||
from asyncio_mqtt import Client
|
||||
import json
|
||||
import fabapi
|
||||
from timer import Timer
|
||||
|
||||
BFFHD_HOST = "127.0.0.1"
|
||||
BFFHD_HOST = "localhost"
|
||||
MQTT_HOST = "127.0.0.1"
|
||||
MACHINE_URN = ""
|
||||
READER_ID = ""
|
||||
MACHINE_URN = "urn:fabaccess:resource:MachineA2"
|
||||
READER_ID = "111"
|
||||
|
||||
auth_cap = None
|
||||
session = None
|
||||
|
||||
async def main():
|
||||
done = False
|
||||
auth_cap = None
|
||||
session = None
|
||||
msg = None
|
||||
global auth_cap
|
||||
global session
|
||||
|
||||
async with Client(MQTT_HOST) as client:
|
||||
await client.publish("/cmnd/reader", payload='{"Cmd":"haltPICC"}', qos=2, retain=False)
|
||||
await client.publish("/cmnd/reader", payload='{"Cmd": "message", "MssgID": 0, "AddnTxt":" Karte auflegen"}', qos=2, retain=False)
|
||||
await client.publish(f"/cmnd/reader/{READER_ID}", payload='{"Cmd":"haltPICC"}', qos=2, retain=False)
|
||||
await client.publish(f"/cmnd/reader/{READER_ID}", payload='{"Cmd": "message", "MssgID": 0, "AddnTxt":" Karte auflegen"}', qos=2, retain=False)
|
||||
async with client.filtered_messages(f"/rfid_reader/{READER_ID}") as messages:
|
||||
await client.subscribe("/rfid_reader/#")
|
||||
logging.info(f"Connected to reader {READER_ID} on MQTT Broker {MQTT_HOST}")
|
||||
async for message in messages:
|
||||
response_for_reader = None
|
||||
if not auth_cap:
|
||||
timeout_timer = Timer(10, lambda: handle_timeout(client))
|
||||
timeout_timer = Timer(2, lambda: handle_timeout(client))
|
||||
auth_cap, response_for_reader = await fabapi.connect_with_fabfire_initial(
|
||||
BFFHD_HOST, 59961, message.payload)
|
||||
BFFHD_HOST, 59661, message.payload)
|
||||
elif not session:
|
||||
response_for_reader, session = await fabapi.connect_with_fabfire_step(auth_cap,
|
||||
message.payload)
|
||||
@ -66,13 +68,17 @@ async def main():
|
||||
if response_for_reader:
|
||||
await client.publish(f"/cmnd/reader/{READER_ID}", payload=response_for_reader, qos=2, retain=False)
|
||||
|
||||
await client.publish("/cmnd/reader", payload=msg, qos=2, retain=False)
|
||||
|
||||
async def handle_timeout(client, reader_id):
|
||||
await client.publish(f"/cmnd/reader/{reader_id}", payload='{"Cmd":"haltPICC"}', qos=2,
|
||||
async def handle_timeout(client):
|
||||
global auth_cap
|
||||
global session
|
||||
await client.publish(f"/cmnd/reader/{READER_ID}", payload='{"Cmd":"haltPICC"}', qos=2,
|
||||
retain=False)
|
||||
logging.critical(f"authentication timed out on reader {reader_id}")
|
||||
logging.critical(f"authentication timed out on reader {READER_ID}")
|
||||
auth_cap = None
|
||||
session = None
|
||||
|
||||
if __name__ == "__main__":
|
||||
LOGLEVEL = os.environ.get('LOGLEVEL', 'INFO').upper()
|
||||
logging.basicConfig(level=LOGLEVEL)
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(main())
|
||||
|
Loading…
x
Reference in New Issue
Block a user