MQTT Python 客户端库
# 连接成功回调
def on_connect(client, userdata, flags, rc):
print('Connected with result code '+str(rc))
def on_message(client, userdata, msg):
print(msg.topic+" "+str(msg.payload))
client = mqtt.Client()
client.on_message = on_message
# 建立连接
client.connect('broker.emqx.io', 1883, 60)
# 发布消息
client.publish('emqtt',payload='Hello World',qos=0)
client.loop_forever()