xmqtt-1.py 388 B

12345678910111213141516171819
  1. import paho.mqtt.client as mqtt
  2. # MQTT 代理设置
  3. broker_address = "127.0.0.1"
  4. broker_port = 41883
  5. username = "admin"
  6. password = "public"
  7. # 创建客户端实例
  8. client = mqtt.Client()
  9. # 设置用户名和密码
  10. client.username_pw_set(username, password)
  11. # 连接到 MQTT 代理
  12. client.connect(broker_address, broker_port)
  13. # 可以继续执行 MQTT 操作(发布、订阅等)