2021-02-27 18:01:39 +00:00
|
|
|
#!/usr/bin/python
|
2022-11-06 13:30:11 +00:00
|
|
|
from . import nfc, socket, door, bell
|
|
|
|
from .util import init_logging
|
2021-08-11 05:29:19 +00:00
|
|
|
|
2022-11-06 13:30:11 +00:00
|
|
|
from collections import namedtuple
|
2021-08-11 05:29:19 +00:00
|
|
|
import paho.mqtt.client as mqcl
|
2022-11-06 13:30:11 +00:00
|
|
|
import logging
|
2021-08-09 17:51:21 +00:00
|
|
|
|
2021-08-11 05:19:37 +00:00
|
|
|
def main():
|
2022-11-06 13:30:11 +00:00
|
|
|
import argparse
|
|
|
|
import logging
|
|
|
|
import time
|
|
|
|
|
|
|
|
from .nfc import DoorControlNfc
|
|
|
|
from .socket import DoorControlSocket
|
|
|
|
from .door import Control
|
|
|
|
from .util import init_logging, logger
|
|
|
|
|
2021-08-11 05:19:37 +00:00
|
|
|
parser = argparse.ArgumentParser()
|
2022-11-06 13:30:11 +00:00
|
|
|
parser.add_argument("--serial_port", default="/dev/serial/by-id/usb-Imaginaerraum.de_DoorControl_433632201350535727003F0-if01")
|
|
|
|
parser.add_argument("--bell_port", default="/dev/ttyS2")
|
2021-08-11 05:19:37 +00:00
|
|
|
parser.add_argument("--nfc_fifo", default="/tmp/nfc_fifo")
|
|
|
|
parser.add_argument("--control_socket", default="/tmp/nfc.sock")
|
|
|
|
parser.add_argument("--valid_tokens", default="/etc/door_tokens")
|
|
|
|
parser.add_argument("--log_file", default="/tmp/nfc.log")
|
2022-11-06 17:43:29 +00:00
|
|
|
parser.add_argument("--log_level", default="INFO")
|
2021-08-11 05:19:37 +00:00
|
|
|
parser.add_argument("--mqtt_host", default="10.10.21.2")
|
|
|
|
|
2022-11-06 13:30:11 +00:00
|
|
|
config = parser.parse_args()
|
2021-08-11 05:19:37 +00:00
|
|
|
|
2022-11-06 13:30:11 +00:00
|
|
|
mqttc = mqcl.Client()
|
|
|
|
mqttc.connect_async("10.10.21.2", keepalive=60)
|
|
|
|
mqttc.loop_start()
|
|
|
|
|
2022-11-06 17:43:29 +00:00
|
|
|
init_logging(level=config.log_level, output_file=config.log_file)
|
2021-08-11 05:19:37 +00:00
|
|
|
|
2022-11-06 13:30:11 +00:00
|
|
|
logger().info("Starting control")
|
|
|
|
control = Control(config, mqttc)
|
|
|
|
control.start()
|
|
|
|
|
|
|
|
logger().info("Starting NFC")
|
|
|
|
nfc = DoorControlNfc(config, control, mqttc)
|
|
|
|
nfc.start()
|
|
|
|
|
|
|
|
logger().info("Starting socket")
|
|
|
|
socket = DoorControlSocket(config, control, nfc)
|
|
|
|
socket.start()
|
2021-08-11 05:19:37 +00:00
|
|
|
|
2022-11-06 13:30:11 +00:00
|
|
|
logger().info("Starting bell")
|
|
|
|
def door_is_open():
|
|
|
|
return control.state() == control.target() == door.constants.state.OPEN
|
|
|
|
bell_control = bell.Control(config.bell_port, door_is_open)
|
|
|
|
bell_control.start()
|
|
|
|
|
|
|
|
while True:
|
|
|
|
time.sleep(60)
|