嗨,我正在使用Paho的Python Mqtt-Client来接收从物联网板(NodeMCU)发布的IR-Senor值。这是我的代码。
# Defining logging call-back for debugging.
def on_log(client,userdata,level,buf):
print(str(level)+" "+str(buf))
# Defining call-back to be called upon connection of client with broker.
def on_connect(client,userdata,flags,rc):
print("Connected to broker with result code "+str(rc));
# Subscribing to required topic.
client.subscribe(MQTT_CONST['bell_topic'])
# Defining call-back for when message is published to a subscribed topic.
def on_message(client,userdata,msg):
print(str(msg.payload))
# Attaching callbacks to Client.
client = mqtt.Client(client_id='Python_Client')
client.on_log = on_log
client.on_connect = on_connect
client.on_message = on_message
client.username_pw_set(MQTT_CONST['mqtt_user_name'],MQTT_CONST['mqtt_password'])
# Connecting to Broker.
client.connect(MQTT_CONST['mqtt_broker_address'],MQTT_CONST['mqtt_port'],60)
client.loop_forever()
我有信心微控制器上的Arduino MQTT客户端可以正常工作,因为我使用了另一个应用程序,该应用程序订阅了传感器主题,并且可以很好地接收微控制器发送的有效负载。
由于某种原因,我似乎无法在使用python的linux机器上做到这一点。我究竟做错了什么?如果正在使用,我正在使用mqtt.beebotte.com:1883。