我想用一个额外的mqtt-client启动一个apache-server。我在生产中使用Django和Apache。要启动我的mqqt客户端,我编辑了wsgi.py它,如果我使用的是开发服务器(python3 manage.py runserver),则可以正常运行。但是它不能在生产中工作。请问有什么帮助或有想法如何让apache在生产中起作用吗?wsgi.py:import osimport threadingimport logginglogger = logging.getLogger('mqtt')from django.core.wsgi import get_wsgi_applicationos.environ.setdefault("DJANGO_SETTINGS_MODULE", "iot.settings")from iot.settings import MQTT_CONNECTION, MQTT_BROKERif MQTT_CONNECTION: logger.debug('Connecting to Broker...') try: from utils_mqtt_client.mqtt_client import run_client run_client() except Exception as e: logger.debug('Could not conntect to MQTT Broker:\n\t {}'.format(e))else: logger.debug('Starting without MQTT connection')application = get_wsgi_application()mqqt客户端:import jsonimport threadingimport loggingimport paho.mqtt.client as mqttfrom device.models import Devicefrom value.models import Valuefrom iot.settings import MQTT_BROKERlogger = logging.getLogger('mqtt')topics = ['config']CLIENT = mqtt.Client('webserver')# [...]def run_client(): devices = Device.objects.all() CLIENT.on_connect = on_connect CLIENT.on_message = on_message for device in devices: subscribe(CLIENT, device) CLIENT.connect(MQTT_BROKER) CLIENT.loop_start()
添加回答
举报
0/150
提交
取消