我正在使用这个python脚本来实现一个Paho( mqtt )订阅者,但是我无法获得任何响应消息。我可以通过使用mosquitto_sub -t "" -d -h -p 8883 --psk foo --psk-identity bar --insecure --tls-version tlsv1订阅mqtt命令提示符
import paho.mqtt.client as mqtt
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.
client.subscribe("*********")
def on_message(client, userdata, msg):
print(msg.topic+" "+str(msg.payload))
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("*********", 8883, 60)
client.loop_forever()当我运行上面的python脚本时,它不会响应任何错误或消息,而是继续使用循环,我还逐行运行它,当我运行client.connect("*********", 8883, 60)时,它只显示。请注意,如果没有psk和psk-身份,我们不能连接到代理。
谢谢
发布于 2020-01-03 05:20:00
请仔细检查你的话题,有时会丢失/或#因为这个问题。
或
尝尝这个
def on_message(client, userdata, msg):
print("Message Recieved from broker: " + msg.payload.decode())https://stackoverflow.com/questions/52281398
复制相似问题