2021-08-18 16:48:17 +00:00
|
|
|
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")
|
2021-08-19 08:29:23 +00:00
|
|
|
print(client.subscribe("mlmAccess/actor/102/action"))
|
2021-08-18 16:48:17 +00:00
|
|
|
print("Publishing message to topic","mlmAccess/pair/request/actor")
|
2021-08-19 08:29:23 +00:00
|
|
|
print(client.publish("mlmAccess/actor/102/status", "0", retain=True))
|
2021-08-18 16:48:17 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2021-08-19 08:29:23 +00:00
|
|
|
client = mqtt.Client(client_id="actor-102")
|
|
|
|
client.username_pw_set("actor-102", "YWT2JPOEZH")
|
2021-08-18 16:48:17 +00:00
|
|
|
|
|
|
|
client.on_connect = on_connect
|
|
|
|
client.on_message = on_message
|
|
|
|
|
|
|
|
print("connecting to broker")
|
|
|
|
print(client.connect("localhost", 1883, 60))
|
|
|
|
|
|
|
|
client.loop_forever()
|