From 1b4e49f992ab53b318a04900ef66d9a874d90645 Mon Sep 17 00:00:00 2001 From: xyj <10908227994@qq.com> Date: Thu, 7 Dec 2023 15:27:38 +0800 Subject: [PATCH] update --- MQTT.py | 25 +++++++++++++++++-- else_conf/cron.conf | 5 ++-- test.sh | 2 ++ tool.py | 1 + update.sh | 1 + .../push_stream_test.conf | 2 +- 6 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 test.sh rename conf/push_stream.conf => var_conf/push_stream_test.conf (77%) diff --git a/MQTT.py b/MQTT.py index a6045fd..91f777c 100644 --- a/MQTT.py +++ b/MQTT.py @@ -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 diff --git a/else_conf/cron.conf b/else_conf/cron.conf index a400c01..13f3793 100644 --- a/else_conf/cron.conf +++ b/else_conf/cron.conf @@ -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 diff --git a/test.sh b/test.sh new file mode 100644 index 0000000..351453f --- /dev/null +++ b/test.sh @@ -0,0 +1,2 @@ +#!/bin/bash +echo $device_name \ No newline at end of file diff --git a/tool.py b/tool.py index 32923de..7510830 100644 --- a/tool.py +++ b/tool.py @@ -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) diff --git a/update.sh b/update.sh index 3698759..2a0b71b 100644 --- a/update.sh +++ b/update.sh @@ -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 diff --git a/conf/push_stream.conf b/var_conf/push_stream_test.conf similarity index 77% rename from conf/push_stream.conf rename to var_conf/push_stream_test.conf index fd9bef2..6f4191b 100644 --- a/conf/push_stream.conf +++ b/var_conf/push_stream_test.conf @@ -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