xmqtt-1.py 422 B

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