2023-12-02 10:53:31 +08:00
|
|
|
import json
|
2023-12-04 13:22:54 +08:00
|
|
|
import os
|
2023-12-02 10:53:31 +08:00
|
|
|
import subprocess
|
|
|
|
|
2023-12-04 13:22:54 +08:00
|
|
|
import requests
|
2023-12-02 19:24:31 +08:00
|
|
|
|
2023-12-04 13:22:54 +08:00
|
|
|
mp4_path = '/home/pi/mp4'
|
|
|
|
|
2023-12-02 10:53:31 +08:00
|
|
|
|
2023-12-05 09:31:52 +08:00
|
|
|
def push_stream(client):
|
|
|
|
p = subprocess.Popen(['/bin/bash start_push.sh'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
out, err = p.communicate()
|
|
|
|
output = out.decode('utf-8')
|
|
|
|
client.publish('success', payload=json.dumps(output, ensure_ascii=False), qos=0)
|
2023-12-02 10:53:31 +08:00
|
|
|
|
|
|
|
|
2023-12-05 09:31:52 +08:00
|
|
|
def close_stream(client):
|
|
|
|
p = subprocess.Popen(['/bin/bash stop_push.sh'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
out, err = p.communicate()
|
|
|
|
output = out.decode('utf-8')
|
|
|
|
client.publish('success', payload=json.dumps(output, ensure_ascii=False), qos=0)
|
2023-12-02 10:53:31 +08:00
|
|
|
|
|
|
|
|
2023-12-05 09:14:18 +08:00
|
|
|
def exec_sh(msg, client):
|
2023-12-02 10:53:31 +08:00
|
|
|
cmd = json.loads(msg.payload.decode('utf-8'))["data"]
|
2023-12-05 09:45:55 +08:00
|
|
|
if cmd == "supervisorctl stop __mqtt__" or cmd == "supervisorctl restart __mqtt__":
|
2023-12-05 09:40:57 +08:00
|
|
|
return
|
2023-12-05 09:45:55 +08:00
|
|
|
if cmd == "supervisorctl reload":
|
2023-12-05 09:40:57 +08:00
|
|
|
subprocess.Popen([cmd], shell=True)
|
2023-12-04 10:05:04 +08:00
|
|
|
return
|
2023-12-05 09:08:53 +08:00
|
|
|
p = subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
out, err = p.communicate()
|
|
|
|
output = out.decode('utf-8')
|
2023-12-05 09:14:18 +08:00
|
|
|
client.publish('success', payload=json.dumps(output, ensure_ascii=False), qos=0)
|
2023-12-02 10:53:31 +08:00
|
|
|
|
|
|
|
|
2023-12-05 09:31:52 +08:00
|
|
|
def get_status(client):
|
|
|
|
p = subprocess.Popen(['supervisorctl status'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
out, err = p.communicate()
|
|
|
|
output = out.decode('utf-8')
|
|
|
|
client.publish('success', payload=json.dumps(output, ensure_ascii=False), qos=0)
|
|
|
|
|
|
|
|
|
|
|
|
def update(client):
|
|
|
|
p = subprocess.Popen(['/bin/bash update.sh'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
out, err = p.communicate()
|
|
|
|
output = out.decode('utf-8')
|
|
|
|
client.publish('success', payload=json.dumps(output, ensure_ascii=False), qos=0)
|
2023-12-02 18:32:17 +08:00
|
|
|
|
|
|
|
|
2023-12-04 13:22:54 +08:00
|
|
|
def get_list_record():
|
|
|
|
data = {
|
|
|
|
"data": os.listdir(mp4_path)
|
|
|
|
}
|
|
|
|
requests.post("http://shop.lihaink.cn/api/index/file_list", json=data)
|
2023-12-02 20:00:27 +08:00
|
|
|
|
|
|
|
|
2023-12-02 19:24:31 +08:00
|
|
|
def get_record(msg, client):
|
2023-12-04 13:22:54 +08:00
|
|
|
filename = json.loads(msg.payload.decode('utf-8'))["data"]
|
|
|
|
if filename is None or filename == '':
|
|
|
|
client.publish('error', payload='没有该文件', qos=1)
|
2023-12-02 19:24:31 +08:00
|
|
|
return
|
2023-12-04 13:22:54 +08:00
|
|
|
files = {filename: open(os.path.join(mp4_path, filename), 'rb'), "Content-Type": "application/octet-stream"}
|
|
|
|
requests.post("https://shop.lihaink.cn/api/index/upload", files=files)
|
2023-12-05 16:21:08 +08:00
|
|
|
|
|
|
|
def sensor_data_upload(client):
|
|
|
|
p = subprocess.Popen(['/bin/bash update.sh'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|