コード例 #1
0
ファイル: xbee_gateway.py プロジェクト: blalor/home-automator
def main():
    from support import daemonizer, log_config
    from config import config_data as config
    
    import signal
    
    basedir = os.path.abspath(os.path.dirname(__file__))
    
    daemonizer.createDaemon()
    log_config.init_logging(basedir + "/logs/dispatcher.log")
    
    # log_config.init_logging_stdout()
    
    dispatcher = XBeeDispatcher(
        broker_host = config.message_broker.host,
        serial_port = sys.argv[1],
        baudrate = int(sys.argv[2])
    )
    
    # The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.
    signal.signal(signal.SIGHUP, signal.SIG_IGN)
    signal.signal(signal.SIGQUIT, lambda signum, frame: dispatcher.shutdown())
    signal.signal(signal.SIGTERM, lambda signum, frame: dispatcher.shutdown())
    
    try:
        dispatcher.process_forever()
    except KeyboardInterrupt:
        logging.info("Interrupt caught, shutting down")
    except:
        logging.error("unhandled exception", exc_info=True)
    finally:
        logging.debug("cleaning up")
        dispatcher.shutdown()
        log_config.shutdown()
コード例 #2
0
def main():
    from support import daemonizer, log_config
    import logging
    import signal
    
    basedir = os.path.abspath(os.path.dirname(__file__))
    
    daemonizer.createDaemon()
    log_config.init_logging(basedir + "/logs/voltometer.log")
    
    # log_config.init_logging_stdout()
    
    signal.signal(signal.SIGHUP, signal.SIG_IGN)
    
    vd = VoltometerDriver('00:11:22:33:44:55:66:e2')
    
    try:
        vd.process_forever()
    
    except:
        logging.fatal("something bad happened", exc_info = True)
        
    finally:
        vd.shutdown()
        log_config.shutdown()
コード例 #3
0
def main():
    from support import daemonizer, log_config
    from config import config_data as config
    import signal
    
    basedir = os.path.abspath(os.path.dirname(__file__))
    
    ## standard config
    daemonizer.createDaemon()
    signal.signal(signal.SIGHUP, signal.SIG_IGN)
    
    log_config.init_logging(basedir + "/logs/db_logger.log")
    
    ## debug config
    # log_config.init_logging_stdout()
    
    try:
        dbl = DBLogger(config.message_broker.host, basedir + '/sensors.db')
        
        signal.signal(signal.SIGQUIT, lambda signum, frame: dbl.shutdown())
        signal.signal(signal.SIGTERM, lambda signum, frame: dbl.shutdown())
        signal.signal(signal.SIGINT, lambda signum, frame: dbl.shutdown())
        
        dbl.process_forever()
    except:
        logging.critical("uncaught exception", exc_info = True)
    finally:
        log_config.shutdown()
コード例 #4
0
def main():
    from support import daemonizer, log_config
    from config import config_data as config

    basedir = os.path.abspath(os.path.dirname(__file__))

    daemonizer.createDaemon()
    log_config.init_logging(basedir + "/logs/xmlrpc_server.log")

    # log_config.init_logging_stdout()

    worker = BrokerWorker(config.message_broker.host)
    worker.daemon = True
    worker.start()

    server = SimpleXMLRPCServer.SimpleXMLRPCServer(
        (config.xmlrpc_server.host, config.xmlrpc_server.port), allow_none=True
    )

    # server.register_introspection_functions()
    server.register_instance(MessagingProxy(worker))

    try:
        server.serve_forever()
    except:
        logging.critical("exception", exc_info=True)
    finally:
        worker.shutdown()
        logging.debug("joining")
        worker.join()

    log_config.shutdown()
コード例 #5
0
def main():
    from support import daemonizer, log_config
    import logging
    import signal
    
    basedir = os.path.abspath(os.path.dirname(__file__))
    
    daemonizer.createDaemon()
    log_config.init_logging(basedir + "/logs/sprinkler.log")
    
    signal.signal(signal.SIGHUP, signal.SIG_IGN)
    
    sc = SprinklerConsumer('00:11:22:33:44:55:66:1d')
    
    try:
        sc.process_forever()
    except:
        logging.error("unhandled exception", exc_info=True)
    finally:
        sc.shutdown()
        log_config.shutdown()
コード例 #6
0
def main(argv=None):
    from support import daemonizer, log_config
    import logging
    
    basedir = os.path.abspath(os.path.dirname(__file__))
    
    daemonizer.createDaemon()
    log_config.init_logging(basedir + "/logs/xbee_network_monitor.log")
    
    # log_config.init_logging_stdout()
    
    mon = XBeeNetworkMonitor()
    
    try:
        mon.process_forever()
    
    except:
        logging.fatal("something bad happened", exc_info = True)
        
    finally:
        mon.shutdown()
        log_config.shutdown()
コード例 #7
0
def main():
    from support import daemonizer, log_config
    import logging
    import signal
    
    basedir = os.path.abspath(os.path.dirname(__file__))
    
    daemonizer.createDaemon()
    log_config.init_logging(basedir + "/logs/oil_tank.log")
    
    # log_config.init_logging_stdout()
    
    signal.signal(signal.SIGHUP, signal.SIG_IGN)
    
    fc = FuelOilTankConsumer(['00:11:22:33:44:55:66:cf'])
    
    try:
        fc.process_forever()
    except:
        logging.error("unhandled exception", exc_info=True)
    finally:
        fc.shutdown()
        log_config.shutdown()
コード例 #8
0
def main():
    from support import daemonizer, log_config
    import signal
    import logging

    basedir = os.path.abspath(os.path.dirname(__file__))

    daemonizer.createDaemon()
    log_config.init_logging(basedir + "/logs/env_node.log")

    # log_config.init_logging_stdout()

    signal.signal(signal.SIGHUP, signal.SIG_IGN)

    c = EnvironmentalNodeConsumer(("00:11:22:33:44:55:66:dc", "00:11:22:33:44:55:66:22"))

    try:
        c.process_forever()
    except:
        logging.error("unhandled exception", exc_info=True)
    finally:
        c.shutdown()
        log_config.shutdown()
コード例 #9
0
def main():
    from support import daemonizer, log_config
    import logging
    import signal
    
    basedir = os.path.abspath(os.path.dirname(__file__))
    
    daemonizer.createDaemon()
    log_config.init_logging(basedir + "/logs/xbee_lt.log")
    
    # log_config.init_logging_stdout()
    
    signal.signal(signal.SIGHUP, signal.SIG_IGN)
    
    pc = LightTempConsumerRabbit(('00:11:22:33:44:55:66:a5', '00:11:22:33:44:55:66:7d'))
    
    try:
        pc.process_forever()
    except:
        logging.error("unhandled exception", exc_info=True)
    finally:
        pc.shutdown()
        log_config.shutdown()
コード例 #10
0
def main():
    basedir = os.path.abspath(os.path.dirname(__file__))
    
    daemonizer.createDaemon()
    
    handler = logging.handlers.RotatingFileHandler(basedir + "/logs/calibration.log",
                                                   maxBytes=(5 * 1024 * 1024),
                                                   backupCount=5)
    
    handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)s [%(threadName)s] %(name)s -- %(message)s"))
    
    logging.getLogger().addHandler(handler)
    logging.getLogger().setLevel(logging.INFO)
    
    signal.signal(signal.SIGHUP, signal.SIG_IGN)
    
    c = EnvironmentalNodeCalibrator(basedir + '/calibration.db')
    
    try:
        c.process_forever()
    finally:
        c.shutdown()
        logging.shutdown()