This commit is contained in:
xyj 2023-12-07 15:27:38 +08:00
parent a2210b4624
commit 1b4e49f992
6 changed files with 30 additions and 6 deletions

25
MQTT.py
View File

@ -5,16 +5,37 @@ import paho.mqtt.client as mqtt
from tool import push_stream, close_stream, update, exec_sh, get_record, get_list_record, get_status
import os
device_name = os.getenv('device_name')
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'))
dev_num = origin_data['device_name']
if dev_num is None:
client.publish('error', payload='dev_num must be supplied', qos=0)
return False
if dev_num != device_name:
return False
return True
# Message receiving callback
def on_message(client, userdata, msg):
if valid(msg, client) is False:
return
try:
data = json.loads(msg.payload.decode('utf-8'))["msg"]
origin_data = json.loads(msg.payload.decode('utf-8'))
data = origin_data["msg"]
if data is None:
client.publish('error', payload='msg must be supplied', qos=0)
return
if data == "push_stream":
# 启动推流视频
push_stream(client)
@ -38,7 +59,7 @@ def on_message(client, userdata, msg):
get_status(client)
else:
# 错误类型
client.publish('success', payload='No Such Type', qos=0)
client.publish('error', payload='No Such Type', qos=0)
except Exception as e:
pass

View File

@ -1,4 +1,3 @@
#
0 0 * * * /usr/bin/bash /home/pi/delete_than24.sh
*/15 * * * * /usr/bin/bash /home/pi/cron_delete_mp4.sh
0 0 * * * /usr/bin/bash /home/pi/lot_manager/delete_than.sh
*/15 * * * * /usr/bin/bash /home/pi/lot_manager/cron_delete_mp4.sh

2
test.sh Normal file
View File

@ -0,0 +1,2 @@
#!/bin/bash
echo $device_name

View File

@ -52,6 +52,7 @@ def update(client):
def get_list_record():
data = {
"data": os.listdir(mp4_path)
}
requests.post("http://shop.lihaink.cn/api/index/file_list", json=data)

View File

@ -4,6 +4,7 @@ set -e
git pull origin master --force
# 配置文件复制到supervisor管理
cp -r conf/*.conf /etc/supervisor/conf.d/
cp -r var_conf/push_stream_ + $device_name
# 更新配置文件
supervisorctl reread
supervisorctl update

View File

@ -1,6 +1,6 @@
[program:push_stream]
directory=/home/pi/lot_manager
command=/usr/bin/ffmpeg -rtsp_transport tcp -re -i rtsp://admin:123456@192.168.0.123:554/mpeg4 -c copy -preset fast -r 20 -flvflags no_duration_filesize -f rtsp -rtsp_transport tcp rstp://47.108.186.87:554/live/test
command=/usr/bin/ffmpeg -rtsp_transport tcp -re -i rtsp://admin:123456@192.168.0.123:554/mpeg4 -c copy -preset fast -r 20 -flvflags no_duration_filesize -f rtsp -rtsp_transport tcp rtsp://47.108.186.87:554/live/test
user=pi
autostart=false
autorestart=true