update
This commit is contained in:
parent
57fb9b9ea6
commit
0d9fa75119
15
MQTT.py
15
MQTT.py
|
@ -14,8 +14,7 @@ def on_connect(client, userdata, flags, rc):
|
||||||
|
|
||||||
|
|
||||||
def valid(msg, client):
|
def valid(msg, client):
|
||||||
import os
|
|
||||||
device_name = os.getenv('device_name')
|
|
||||||
origin_data = json.loads(msg.payload.decode('utf-8'))
|
origin_data = json.loads(msg.payload.decode('utf-8'))
|
||||||
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)
|
||||||
|
@ -23,18 +22,18 @@ def valid(msg, client):
|
||||||
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
|
||||||
client.publish('error', payload=device_name, qos=0)
|
|
||||||
if origin_data['device_name'] != device_name:
|
|
||||||
return False
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
# Message receiving callback
|
# Message receiving callback
|
||||||
def on_message(client, userdata, msg):
|
def on_message(client, userdata, msg):
|
||||||
if valid(msg, client) is False:
|
# if valid(msg, client) is False:
|
||||||
client.publish('error', payload='验证失败', qos=0)
|
# client.publish('error', payload='验证失败', qos=0)
|
||||||
return
|
# return
|
||||||
# print("验证通过")
|
# print("验证通过")
|
||||||
|
import os
|
||||||
|
device_name = os.getenv('device_name')
|
||||||
|
client.publish('error', payload=device_name, qos=0)
|
||||||
client.publish('success', payload='验证通过', qos=0)
|
client.publish('success', payload='验证通过', qos=0)
|
||||||
try:
|
try:
|
||||||
origin_data = json.loads(msg.payload.decode('utf-8'))
|
origin_data = json.loads(msg.payload.decode('utf-8'))
|
||||||
|
|
Loading…
Reference in New Issue