我想使用由Eclipse提供的paho python庫連接到Mosquitto服務器以發佈和訂閱消息。目前,我有Mosquitto守護進程運行,並且我能夠發佈和訂閱以及經紀人精確地指導主題。我的問題是一旦我嘗試使用Paho圖書館,我可以連接到Mosquitto服務器(經紀人),但我無法接收我訂閱的主題。發佈者和接收者的代碼都能正常工作,但可能有一些我缺少的東西。如果有人幫助我,我會很感激。Paho python客戶端無法正常使用Mosquitto Broker
我的發佈/訂閱代碼如下:
認購人:
import paho.mqtt.client as mqtt
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+ str(rc))
client.subscribe("test")
def on_message(client, userdata, msg):
print("Recieved message " + str(msg.payload) + " " + msg.topic + "Qos= " + str(msg.qos))
client.disconnect()
client = mqtt.Client()
client.connect("localhost", 1883, 60)
client.on_connect = on_connect
client.on_massage = on_message
client.loop_forever()
出版商:
import paho.mqtt.client as mqtt
client = mqtt.Client()
client.connect("localhost", 1883, 60)
client.publish("test", "Hello World!")
client.disconnect();
錯字 - 'client.on_massage = on_message'應該是'client.on_message = on_message' – markroxor