update
This commit is contained in:
parent
8ec6529313
commit
1a54df1897
15
src/MQTT.py
15
src/MQTT.py
|
@ -17,11 +17,13 @@ def on_connect(client, userdata, flags, rc):
|
||||||
|
|
||||||
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'))
|
||||||
dev_num = origin_data['device_name']
|
if 'msg' not in origin_data:
|
||||||
if dev_num is None:
|
client.publish('error', payload='msg must be supplied', qos=0)
|
||||||
client.publish('error', payload='dev_num must be supplied', qos=0)
|
|
||||||
return False
|
return False
|
||||||
if dev_num != device_name:
|
if 'device_name' not in origin_data:
|
||||||
|
client.publish('error', payload='device_name must be supplied', qos=0)
|
||||||
|
return False
|
||||||
|
if origin_data['device_name'] != device_name:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -29,13 +31,12 @@ def valid(msg, client):
|
||||||
# Message receiving callback
|
# Message receiving callback
|
||||||
def on_message(client, userdata, msg):
|
def on_message(client, userdata, msg):
|
||||||
if not valid(msg, client):
|
if not valid(msg, client):
|
||||||
|
# print("验证失败")
|
||||||
return
|
return
|
||||||
|
# print("验证通过")
|
||||||
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"]
|
||||||
if data is None:
|
|
||||||
client.publish('error', payload='msg must be supplied', qos=0)
|
|
||||||
return
|
|
||||||
if data == "push_stream":
|
if data == "push_stream":
|
||||||
# 启动推流视频
|
# 启动推流视频
|
||||||
push_stream(client)
|
push_stream(client)
|
||||||
|
|
Binary file not shown.
|
@ -25,7 +25,11 @@ def close_stream(client):
|
||||||
|
|
||||||
|
|
||||||
def exec_sh(msg, client):
|
def exec_sh(msg, client):
|
||||||
cmd = json.loads(msg.payload.decode('utf-8'))["data"]
|
origin_data = json.loads(msg.payload.decode('utf-8'))
|
||||||
|
if 'data' not in origin_data:
|
||||||
|
client.publish('error', payload='data must be supplied', qos=0)
|
||||||
|
return
|
||||||
|
cmd = origin_data["data"]
|
||||||
if cmd == "supervisorctl stop __mqtt__" or cmd == "supervisorctl restart __mqtt__":
|
if cmd == "supervisorctl stop __mqtt__" or cmd == "supervisorctl restart __mqtt__":
|
||||||
return
|
return
|
||||||
if cmd == "supervisorctl reload":
|
if cmd == "supervisorctl reload":
|
||||||
|
|
Loading…
Reference in New Issue