From d1d2161c723c3d56ff8fb2dcd7ff90345016b8b9 Mon Sep 17 00:00:00 2001 From: xyj <10908227994@qq.com> Date: Sat, 9 Dec 2023 18:57:28 +0800 Subject: [PATCH] update --- MQTT.py | 12 +----------- data_upload.py | 8 +++----- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/MQTT.py b/MQTT.py index 933e540..60fca4a 100644 --- a/MQTT.py +++ b/MQTT.py @@ -15,7 +15,6 @@ def valid(msg, client): if 'device_name' not in origin_data: client.publish('error', payload='device_name must be supplied', qos=0) return False - client.publish('error', payload=device_name, qos=0) if device_name != origin_data['device_name']: return False return True @@ -28,17 +27,12 @@ class MQTTClient: self.topic = topic self.client = mqtt.Client() self.client.on_connect = self.on_connect - self.client.on_disconnect = self.on_disconnect self.client.on_message = self.on_message def on_connect(self, client, userdata, flags, rc): - print("Connected with result code " + str(rc)) self.client.subscribe(self.topic) client.publish('success', payload='成功订阅lot_mqtt' + str(time.time()), qos=0) - def on_disconnect(self, client, userdata, rc): - print("Disconnected with code " + str(rc)) - def on_message(self, client, userdata, msg): if not valid(msg, client): client.publish('error', payload='验证失败', qos=0) @@ -83,10 +77,6 @@ if __name__ == '__main__': while True: try: MQTT.start() - if MQTT.client.is_connected(): - print("连接成功") MQTT.client.loop_forever() except: - print("重新连接") - time.sleep(1) - + time.sleep(15) diff --git a/data_upload.py b/data_upload.py index 76804a0..dea7f4f 100644 --- a/data_upload.py +++ b/data_upload.py @@ -35,7 +35,7 @@ class DataUploadClient: subprocess.Popen(['/usr/bin/bash /home/pi/lot_manager/bash/start_data_upload.sh'], shell=True) def on_disconnect(self, client, userdata, rc): - print("失败,执行本地存储") + # print("失败,执行本地存储") subprocess.Popen(['/usr/bin/bash /home/pi/lot_manager/bash/stop_data_upload.sh'], shell=True) def start(self): @@ -47,9 +47,7 @@ if __name__ == '__main__': while True: try: MQTT.start() - if MQTT.client.is_connected(): - print("连接成功") MQTT.client.loop_forever() except: - print("重新连接") - time.sleep(1) + # print("重新连接") + time.sleep(10)