From f5fc061309589bf53396b323dee90f26fd603466 Mon Sep 17 00:00:00 2001 From: xyj <10908227994@qq.com> Date: Mon, 11 Dec 2023 15:21:25 +0800 Subject: [PATCH] update --- MQTT.py | 5 +++-- data_upload.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/MQTT.py b/MQTT.py index 1b51604..c3d179e 100644 --- a/MQTT.py +++ b/MQTT.py @@ -33,13 +33,13 @@ class MQTTClient: self.password = password # 千万不要指定client_id 不然死翘翘 self.client = mqtt.Client() - 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): if rc == 0: - client.subscribe(self.topic) + self.client.subscribe(self.topic) client.publish('success', payload='成功订阅lot_mqtt,time=' + str(datetime.datetime.now()), qos=0) def on_message(self, client, userdata, msg): @@ -78,6 +78,7 @@ class MQTTClient: pass def start(self): + self.client.username_pw_set(self.username, self.password) self.client.connect(self.broker, self.port) diff --git a/data_upload.py b/data_upload.py index 442e59d..322e651 100644 --- a/data_upload.py +++ b/data_upload.py @@ -20,7 +20,7 @@ class DataUploadClient: self.password = password # 千万不要指定client_id 不然死翘翘 self.client = mqtt.Client() - self.client.username_pw_set(self.username, self.password) + self.client.on_connect = self.on_connect self.client.on_disconnect = self.on_disconnect @@ -33,6 +33,7 @@ class DataUploadClient: subprocess.Popen(['/usr/bin/bash /home/pi/lot_manager/bash/stop_data_upload.sh'], shell=True) def start(self): + self.client.username_pw_set(self.username, self.password) self.client.connect(self.broker, self.port)