import mqtt import time import logging import sys root = logging.getLogger('root') root.setLevel(logging.DEBUG) handler = logging.StreamHandler(sys.stdout) handler.setLevel(logging.DEBUG) formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') handler.setFormatter(formatter) root.addHandler(handler) def print_msg(client, userdata, message): print("Received ", message.topic, ": ", str(message.payload)) c = mqtt.mqtt_client('test', '192.168.0.2', username='', password='') c.add_callback('ambient/#', print_msg) while True: time.sleep(1)