#!/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_host", default=None) parser.add_argument("--log_level", default="INFO") parser.add_argument("--mqtt_host", default="mqtt.local.imaginaerraum.de") config = parser.parse_args() mqttc = mqcl.Client() mqttc.connect_async("10.10.21.2", keepalive=60) mqttc.loop_start() log_host = None if config.log_host != None: log_host = config.log_host.split(':') log_host = (log_host[0], int(log_host[1])) init_logging(level=config.log_level, output_file=config.log_file, output_host=log_host) logger().info("Starting control") control = Control(config, mqttc) control.start() logger().info("Starting NFC") nfc = DoorControlNfc(config, control, mqttc) nfc.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, mqttc, door_is_open) bell_control.start() logger().info("Starting socket") socket = DoorControlSocket(config, control, bell_control, nfc) socket.start() while True: time.sleep(60)