import paho.mqtt.client as mqtt # The callback for when the client receives a CONNACK response from the server. def on_connect(client, userdata, flags, rc): print("Connected with result code "+str(rc)) # Subscribing in on_connect() means that if we lose the connection and # reconnect then subscriptions will be renewed. print("Subscribing to topic","mlmAccess/pair/response/actor") print(client.subscribe("mlmAccess/actor/102/action")) print("Publishing message to topic","mlmAccess/pair/request/actor") print(client.publish("mlmAccess/actor/102/status", "0", retain=True)) def on_message(client, userdata, message): print("message received " ,str(message.payload.decode("utf-8"))) print("message topic=",message.topic) print("message qos=",message.qos) print("message retain flag=",message.retain) client = mqtt.Client(client_id="actor-102") client.username_pw_set("actor-102", "YWT2JPOEZH") client.on_connect = on_connect client.on_message = on_message print("connecting to broker") print(client.connect("localhost", 1883, 60)) client.loop_forever()