This commit is contained in:
xyj 2023-12-07 19:07:47 +08:00
parent c02e314338
commit 6769ea5b71
1 changed files with 2 additions and 2 deletions

View File

@ -11,19 +11,19 @@ def on_connect(client, userdata, flags, rc):
if rc == 0: if rc == 0:
client.subscribe('lot_mqtt') client.subscribe('lot_mqtt')
def valid(msg, client): def valid(msg, client):
p = subprocess.Popen(['cat /home/pi/device_name'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = subprocess.Popen(['cat /home/pi/device_name'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate() out, err = p.communicate()
device_name = out.decode('utf-8') device_name = out.decode('utf-8')
origin_data = json.loads(msg.payload.decode('utf-8')) origin_data = json.loads(msg.payload.decode('utf-8'))
device_name = str(device_name)
if 'msg' not in origin_data: if 'msg' not in origin_data:
client.publish('error', payload='msg must be supplied', qos=0) client.publish('error', payload='msg must be supplied', qos=0)
return False return False
if 'device_name' not in origin_data: if 'device_name' not in origin_data:
client.publish('error', payload='device_name must be supplied', qos=0) client.publish('error', payload='device_name must be supplied', qos=0)
return False return False
if origin_data['device_name'] != device_name: if str(origin_data['device_name']) != str(device_name):
return False return False
return True return True