server/mock-actor/mock-actor.py
Dorian Zedler cbffbc92a6
- Some better logging
- Split pairing into seperate class
2021-08-19 10:29:23 +02:00

28 lines
No EOL
1.1 KiB
Python

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()