This commit is contained in:
xyj 2023-12-18 11:25:10 +08:00
parent 55479f49b7
commit 8db51ceb4d
2 changed files with 8 additions and 8 deletions

View File

@ -1,4 +1,4 @@
import json
import time
import paho.mqtt.client as mqtt
@ -25,7 +25,7 @@ class DataUploadClient:
def on_connect(self, client, userdata, flags, rc):
global times
times = 6
self.client.publish(info_topic, payload=json.dumps(subscribe_topic + ':连接成功,执行数据推送和本地存储'), qos=0)
self.client.publish(info_topic, payload=publish_payload(200, subscribe_topic + ':连接成功,执行数据推送和本地存储'), qos=0)
subprocess.Popen(['/usr/bin/bash /home/pi/lot_manager/bash/start_data_upload.sh'], shell=True)
def on_disconnect(self, client, userdata, rc):

12
tool.py
View File

@ -10,7 +10,7 @@ from config import mp4_path, post_record_list_url, post_record_url, info_topic
# 统一返回
def publish_payload(code, msg):
return json.dumps({
"code": 200,
"code": code,
"msg": msg
}, ensure_ascii=False)
@ -32,7 +32,7 @@ def push_stream(client):
stderr=subprocess.PIPE)
out, err = p.communicate()
output = out.decode('utf-8').strip()
client.publish(info_topic, payload=publish_payload(200, json.dumps(output, ensure_ascii=False)), qos=0)
client.publish(info_topic, payload=publish_payload(200, output), qos=0)
def close_stream(client):
@ -42,7 +42,7 @@ def close_stream(client):
stderr=subprocess.PIPE)
out, err = p.communicate()
output = out.decode('utf-8').strip()
client.publish(info_topic, payload=publish_payload(code=200, msg=json.dumps(output, ensure_ascii=False)), qos=0)
client.publish(info_topic, payload=publish_payload(code=200, msg=output), qos=0)
def exec_sh(msg, client):
@ -62,7 +62,7 @@ def exec_sh(msg, client):
p = subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
output = out.decode('utf-8').strip()
client.publish(info_topic, payload=publish_payload(code=200, msg=json.dumps(output, ensure_ascii=False)), qos=0)
client.publish(info_topic, payload=publish_payload(code=200, msg=output), qos=0)
def get_status(client):
@ -72,7 +72,7 @@ def get_status(client):
stderr=subprocess.PIPE)
out, err = p.communicate()
output = out.decode('utf-8').strip()
client.publish(info_topic, payload=publish_payload(code=200, msg=json.dumps(output, ensure_ascii=False)), qos=0)
client.publish(info_topic, payload=publish_payload(code=200, msg=output), qos=0)
def update(client):
@ -82,7 +82,7 @@ def update(client):
stderr=subprocess.PIPE)
out, err = p.communicate()
output = out.decode('utf-8').strip()
client.publish(info_topic, payload=publish_payload(code=200, msg=json.dumps(output, ensure_ascii=False)),
client.publish(info_topic, payload=publish_payload(code=200, msg=output),
qos=0)