diff --git a/apps/mqtt/client.py b/apps/mqtt/client.py index 04452d14..60673dbb 100644 --- a/apps/mqtt/client.py +++ b/apps/mqtt/client.py @@ -5,6 +5,7 @@ import paho.mqtt.client as mqtt import logging import json from django.conf import settings +import traceback BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, BASE_DIR) @@ -29,16 +30,16 @@ def on_message(mqttc: mqtt, userdata, msg): payload = json.loads(msg.payload) if topic == 'datachange_S_KIO_Project': print(payload) - mqttc.publish('testtopic/#', 'ok') + mqttc.publish('testtopic', 'ok') def start_mqtt(): - if settings.MQTT_ENABLE: + if settings.MQTT_ENABLED: client = mqtt.Client(callback_api_version=mqtt.CallbackAPIVersion.VERSION2, client_id=settings.BASE_PROJECT_CODE) client.on_connect = on_connect client.on_message = on_message # client.enable_logger(_logger) client.connect(host=settings.MQTT_HOST,port=settings.MQTT_PORT) client.loop_forever() - + if __name__ == '__main__': start_mqtt() \ No newline at end of file