From a6a9f61ff514302ce887f7b477fa9d7efe79672c Mon Sep 17 00:00:00 2001 From: xyj <10908227994@qq.com> Date: Mon, 11 Dec 2023 15:19:35 +0800 Subject: [PATCH] update --- MQTT.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/MQTT.py b/MQTT.py index 8c98163..1b51604 100644 --- a/MQTT.py +++ b/MQTT.py @@ -33,13 +33,14 @@ class MQTTClient: self.password = password # 千万不要指定client_id 不然死翘翘 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_message = self.on_message def on_connect(self, client, userdata, flags, rc): - client.subscribe(self.topic) - client.publish('success', payload='成功订阅lot_mqtt,time=' + str(datetime.datetime.now()), qos=0) + if rc == 0: + client.subscribe(self.topic) + client.publish('success', payload='成功订阅lot_mqtt,time=' + str(datetime.datetime.now()), qos=0) def on_message(self, client, userdata, msg): if not valid(msg, client):