update
This commit is contained in:
parent
f67220d983
commit
e1b856c3a7
25
MQTT.py
25
MQTT.py
|
@ -6,23 +6,20 @@ import paho.mqtt.client as mqtt
|
|||
from tool import push_stream, close_stream, update, exec_sh, get_record, get_list_record, get_status
|
||||
|
||||
|
||||
|
||||
|
||||
def on_connect(client, userdata, flags, rc):
|
||||
if rc == 0:
|
||||
client.subscribe('lot_mqtt')
|
||||
|
||||
|
||||
def valid(msg, client):
|
||||
|
||||
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)
|
||||
return False
|
||||
if 'device_name' not in origin_data:
|
||||
client.publish('error', payload='device_name must be supplied', qos=0)
|
||||
return False
|
||||
return True
|
||||
# def valid(msg, client):
|
||||
# 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)
|
||||
# return False
|
||||
# if 'device_name' not in origin_data:
|
||||
# client.publish('error', payload='device_name must be supplied', qos=0)
|
||||
# return False
|
||||
# return True
|
||||
|
||||
|
||||
# Message receiving callback
|
||||
|
@ -34,7 +31,7 @@ def on_message(client, userdata, msg):
|
|||
import os
|
||||
# device_name = os.environ['device_name']
|
||||
# client.publish('error', payload=device_name, qos=0)
|
||||
client.publish('success', payload='验证通过', qos=0)
|
||||
# client.publish('success', payload='验证通过', qos=0)
|
||||
try:
|
||||
origin_data = json.loads(msg.payload.decode('utf-8'))
|
||||
data = origin_data["msg"]
|
||||
|
@ -76,7 +73,7 @@ def exec_shutdown():
|
|||
if __name__ == '__main__':
|
||||
while True:
|
||||
try:
|
||||
client = mqtt.Client(client_id=os.getenv('device_name'))
|
||||
client = mqtt.Client(client_id='s')
|
||||
client.username_pw_set("demo", "123456")
|
||||
# Specify callback function
|
||||
client.on_connect = on_connect
|
||||
|
|
Loading…
Reference in New Issue