61 lines
1.4 KiB
Python
Raw Normal View History

2022-02-04 19:46:15 +01:00
from MqttPublish import MqttPublish
from OpcUaRequester import OpcUaRequester
from loguru import logger
import argparse
import configparser
import threading
import queue
deathBell = threading.Event()
def exceptHook(args):
global deathBell
logger.error("Exception in thread caught: {}".format(args))
deathBell.set()
logger.error("rang the death bell")
logger.info("opcua2mqtt bridge starting")
parser = argparse.ArgumentParser(description="example1")
parser.add_argument('--config', '-f',
help='Config file, default is $pwd/config.json',
required=False,
default='./config.json')
args = parser.parse_args()
config = configparser.ConfigParser()
config.read(args.config)
queue = queue.Queue()
publishThread = MqttPublish(config, queue)
publishThread.start()
logger.info("MqttPublish started")
opcuaThread = OpcUaRequester(config, queue)
opcuaThread.start()
logger.info("OpcUaRequest started")
threading.excepthook = exceptHook
logger.info("Threading excepthook set")
logger.info("opcua2mqtt bridge is running")
deathBell.wait()
logger.error("opcua2mqtt bridge is dying")
publishThread.stop()
logger.error("publishThread stopped")
opcuaThread.stop()
logger.error("opcuaThread stopped")
publishThread.join()
logger.error("publishThread joined")
opcuaThread.join()
logger.error("opcuaThread joined")
logger.error("opcua2mqtt bridge is terminated")