1234567891011121314151617181920 |
- import paho.mqtt.client as mqtt
- # MQTT 代理设置
- # broker_address = "127.0.0.1"
- broker_address = "10.10.60.237"
- broker_port = 41883
- username = "admin"
- password = "public"
- # 创建客户端实例
- client = mqtt.Client()
- # 设置用户名和密码
- client.username_pw_set(username, password)
- # 连接到 MQTT 代理
- client.connect(broker_address, broker_port)
- # 可以继续执行 MQTT 操作(发布、订阅等)
|