MQTT Python 客户端库

    1. # 连接成功回调
    2. def on_connect(client, userdata, flags, rc):
    3. print('Connected with result code '+str(rc))
    4. def on_message(client, userdata, msg):
    5. print(msg.topic+" "+str(msg.payload))
    6. client = mqtt.Client()
    7. client.on_message = on_message
    8. # 建立连接
    9. client.connect('broker.emqx.io', 1883, 60)
    10. # 发布消息
    11. client.publish('emqtt',payload='Hello World',qos=0)
    12. client.loop_forever()

    Paho Python MQTT 5.0 支持