This commit is contained in:
xyj 2023-12-11 15:19:35 +08:00
parent 62fb681592
commit a6a9f61ff5
1 changed files with 4 additions and 3 deletions

View File

@ -33,11 +33,12 @@ class MQTTClient:
self.password = password self.password = password
# 千万不要指定client_id 不然死翘翘 # 千万不要指定client_id 不然死翘翘
self.client = mqtt.Client() self.client = mqtt.Client()
# self.client.username_pw_set(self.username, self.password) self.client.username_pw_set(self.username, self.password)
self.client.on_connect = self.on_connect self.client.on_connect = self.on_connect
self.client.on_message = self.on_message self.client.on_message = self.on_message
def on_connect(self, client, userdata, flags, rc): def on_connect(self, client, userdata, flags, rc):
if rc == 0:
client.subscribe(self.topic) client.subscribe(self.topic)
client.publish('success', payload='成功订阅lot_mqtt,time=' + str(datetime.datetime.now()), qos=0) client.publish('success', payload='成功订阅lot_mqtt,time=' + str(datetime.datetime.now()), qos=0)