From 8db51ceb4d1c1fee8ac44928deaca2d2de1fb834 Mon Sep 17 00:00:00 2001 From: xyj <10908227994@qq.com> Date: Mon, 18 Dec 2023 11:25:10 +0800 Subject: [PATCH] update --- data_upload.py | 4 ++-- tool.py | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/data_upload.py b/data_upload.py index f9ed9d0..9f526ee 100644 --- a/data_upload.py +++ b/data_upload.py @@ -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): diff --git a/tool.py b/tool.py index 99916d9..fc00d5e 100755 --- a/tool.py +++ b/tool.py @@ -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)