diff --git a/MQTT.py b/MQTT.py index d25cff5..b645e89 100644 --- a/MQTT.py +++ b/MQTT.py @@ -13,9 +13,6 @@ def on_connect(client, userdata, flags, rc): def valid(msg, client): - p = subprocess.Popen(['cat /home/pi/device_name'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, err = p.communicate() - device_name = out.decode('utf-8') 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,7 +20,7 @@ def valid(msg, client): if 'device_name' not in origin_data: client.publish('error', payload='device_name must be supplied', qos=0) return False - if device_name.casefold() != origin_data['device_name'].casefold(): + if device_name != origin_data['device_name']: return False return True @@ -75,10 +72,12 @@ def exec_shutdown(): import os if __name__ == '__main__': - + p = subprocess.Popen(['cat /home/pi/device_name'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + out, err = p.communicate() + device_name = out.decode('utf-8').strip() while True: try: - client = mqtt.Client(client_id='s') + client = mqtt.Client(client_id=device_name) client.username_pw_set("demo", "123456") # Specify callback function client.on_connect = on_connect diff --git a/__pycache__/tool.cpython-310.pyc b/__pycache__/tool.cpython-310.pyc new file mode 100644 index 0000000..721a189 Binary files /dev/null and b/__pycache__/tool.cpython-310.pyc differ