From 0d9fa75119718ac26af7b76c894f313d54cc3e44 Mon Sep 17 00:00:00 2001 From: xyj <10908227994@qq.com> Date: Thu, 7 Dec 2023 18:44:53 +0800 Subject: [PATCH] update --- MQTT.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/MQTT.py b/MQTT.py index e333e58..59c02bd 100644 --- a/MQTT.py +++ b/MQTT.py @@ -14,8 +14,7 @@ def on_connect(client, userdata, flags, rc): def valid(msg, client): - import os - device_name = os.getenv('device_name') + origin_data = json.loads(msg.payload.decode('utf-8')) if 'msg' not in origin_data: client.publish('error', payload='msg must be supplied', qos=0) @@ -23,18 +22,18 @@ 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 origin_data['device_name'] != device_name: - return False return True # Message receiving callback def on_message(client, userdata, msg): - if valid(msg, client) is False: - client.publish('error', payload='验证失败', qos=0) - return + # if valid(msg, client) is False: + # client.publish('error', payload='验证失败', qos=0) + # return # print("验证通过") + import os + device_name = os.getenv('device_name') + client.publish('error', payload=device_name, qos=0) client.publish('success', payload='验证通过', qos=0) try: origin_data = json.loads(msg.payload.decode('utf-8'))