This commit is contained in:
xyj 2023-12-11 09:09:07 +08:00
parent d1d2161c72
commit 7e738c71f9
2 changed files with 17 additions and 12 deletions

View File

@ -79,4 +79,4 @@ if __name__ == '__main__':
MQTT.start() MQTT.start()
MQTT.client.loop_forever() MQTT.client.loop_forever()
except: except:
time.sleep(15) time.sleep(30)

27
tool.py
View File

@ -8,19 +8,22 @@ mp4_path = '/home/pi/mp4'
def push_stream(client): def push_stream(client):
p = subprocess.Popen(['/bin/bash /home/pi/lot_manager/bash/start_push_stream.sh'], shell=True, p = subprocess.Popen(['/bin/bash /home/pi/lot_manager/bash/start_push_stream.sh'],
shell=True,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE) stderr=subprocess.PIPE)
out, err = p.communicate() out, err = p.communicate()
output = out.decode('utf-8') output = out.decode('utf-8').strip()
client.publish('success', payload=json.dumps(output, ensure_ascii=False), qos=0) client.publish('success', payload=json.dumps(output, ensure_ascii=False), qos=0)
def close_stream(client): def close_stream(client):
p = subprocess.Popen(['/bin/bash /home/pi/lot_manager/bash/stop_push_stream.sh'], shell=True, p = subprocess.Popen(['/bin/bash /home/pi/lot_manager/bash/stop_push_stream.sh'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE) shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = p.communicate() out, err = p.communicate()
output = out.decode('utf-8') output = out.decode('utf-8').strip()
client.publish('success', payload=json.dumps(output, ensure_ascii=False), qos=0) client.publish('success', payload=json.dumps(output, ensure_ascii=False), qos=0)
@ -38,14 +41,17 @@ def exec_sh(msg, client):
return return
p = subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate() out, err = p.communicate()
output = out.decode('utf-8') output = out.decode('utf-8').strip()
client.publish('success', payload=json.dumps(output, ensure_ascii=False), qos=0) client.publish('success', payload=json.dumps(output, ensure_ascii=False), qos=0)
def get_status(client): def get_status(client):
p = subprocess.Popen(['supervisorctl status'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = subprocess.Popen(['supervisorctl status'],
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = p.communicate() out, err = p.communicate()
output = out.decode('utf-8') output = out.decode('utf-8').strip()
client.publish('success', payload=json.dumps(output, ensure_ascii=False), qos=0) client.publish('success', payload=json.dumps(output, ensure_ascii=False), qos=0)
@ -55,14 +61,13 @@ def update(client):
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE) stderr=subprocess.PIPE)
out, err = p.communicate() out, err = p.communicate()
output = out.decode('utf-8') output = out.decode('utf-8').strip()
client.publish('success', payload=json.dumps(output, ensure_ascii=False), qos=0) client.publish('success', payload=json.dumps(output, ensure_ascii=False), qos=0)
def get_list_record(): def get_list_record():
data = { data = {
"data": os.listdir(mp4_path), "data": os.listdir(mp4_path)
"device_name": os.getenv("device_name")
} }
requests.post("http://shop.lihaink.cn/api/index/file_list", json=data) requests.post("http://shop.lihaink.cn/api/index/file_list", json=data)