update
This commit is contained in:
parent
00a58c9e7e
commit
e731336111
32
MQTT.py
32
MQTT.py
|
@ -12,27 +12,25 @@ def on_connect(client, userdata, flags, rc):
|
||||||
client.subscribe('lot_mqtt')
|
client.subscribe('lot_mqtt')
|
||||||
|
|
||||||
|
|
||||||
# def valid(msg, client):
|
def valid(msg, client):
|
||||||
# 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)
|
||||||
# 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
|
||||||
# return True
|
if origin_data['device_name'] != device_name:
|
||||||
|
return False
|
||||||
|
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("验证通过")
|
client.publish('success', payload='验证通过', qos=0)
|
||||||
import os
|
|
||||||
# device_name = os.environ['device_name']
|
|
||||||
client.publish('error', payload=device_name, 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'))
|
||||||
data = origin_data["msg"]
|
data = origin_data["msg"]
|
||||||
|
|
Loading…
Reference in New Issue