Select Git revision

Matthias Stefan Bodenbenner authored
receive.py 1.23 KiB
import time
import logging
import asyncio
import datetime
from wzl import mqtt
### Ask for settings and individual credentials ###
MQTT_USER = ""
MQTT_PASSWORD = ""
# MQTT_BROKER = "127.0.0.1"
# MQTT_PORT = 1883
# MQTT_VHOST = "/"
## to connect to the central MQTT-Broker of MQ-MS use the following settings:
MQTT_BROKER = "wzl-mbroker01.wzl.rwth-aachen.de"
MQTT_PORT = 1883
MQTT_VHOST = "metrology"
### Ask for settings and individual credentials ###
topic = "#" # set topic to subscribe according to MQTT syntax!
qos = 0 # set QoS according to MQTT specifications!
def print_mqtt_message(topic, message):
print("{}\r\n### {} ###\r\n{}\r\n".format(datetime.datetime.utcnow().isoformat() + "Z", topic, message.decode("utf-8")))
if __name__=="__main__":
console_log = logging.StreamHandler()
console_log.setFormatter(mqtt.formatter)
mqtt.logger.addHandler(console_log)
mqtt.logger.setLevel(logging.INFO)
client = mqtt.MQTTSubscriber(MQTT_USER)
client.connect(MQTT_BROKER, MQTT_PORT, MQTT_VHOST + ":"+ MQTT_USER, MQTT_PASSWORD)
client.set_callback("PRINT", print_mqtt_message)
client.subscribe(topic, qos)
while True:
try:
time.sleep(1)
except KeyboardInterrupt:
break