#!/usr/bin/python from . import nfc, socket, door, bell from .util import init_logging from collections import namedtuple import paho.mqtt.client as mqcl import logging def main(): import argparse import logging import time from .nfc import DoorControlNfc from .socket import DoorControlSocket from .door import Control from .util import init_logging, logger parser = argparse.ArgumentParser() parser.add_argument("--serial_port", default="/dev/serial/by-id/usb-Imaginaerraum.de_DoorControl_433632201350535727003F0-if01") parser.add_argument("--bell_port", default="/dev/ttyS2") 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") parser.add_argument("--log_level", default="INFO") parser.add_argument("--mqtt_host", default="10.10.21.2") config = parser.parse_args() mqttc = mqcl.Client() mqttc.connect_async("10.10.21.2", keepalive=60) mqttc.loop_start() init_logging(level=config.log_level, output_file=config.log_file) 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() 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)