Python paho-mqtt连接到MQTT b

2024-06-01 02:42:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用这个python脚本来实现Paho(MQTT)订户,但是我无法获得任何responce消息

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)时,它只显示0。请注意,没有psk和psk身份,我们无法连接到代理。在

谢谢


Tags: 脚本client消息messageondefconnectmsg