first
This commit is contained in:
commit
0bdbeb9cf7
|
@ -0,0 +1,33 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoredPackages">
|
||||
<value>
|
||||
<list size="9">
|
||||
<item index="0" class="java.lang.String" itemvalue="transformers" />
|
||||
<item index="1" class="java.lang.String" itemvalue="fastapi" />
|
||||
<item index="2" class="java.lang.String" itemvalue="typing_extensions" />
|
||||
<item index="3" class="java.lang.String" itemvalue="tokenizers" />
|
||||
<item index="4" class="java.lang.String" itemvalue="sentencepiece" />
|
||||
<item index="5" class="java.lang.String" itemvalue="streamlit" />
|
||||
<item index="6" class="java.lang.String" itemvalue="torch" />
|
||||
<item index="7" class="java.lang.String" itemvalue="huggingface_hub" />
|
||||
<item index="8" class="java.lang.String" itemvalue="starlette" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||
<option name="ignoredErrors">
|
||||
<list>
|
||||
<option value="N801" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="ReassignedToPlainText" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="ShellCheck" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<shellcheck_settings value="SC2239" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
|
@ -0,0 +1,6 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="chatchat" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="agri_chatglm3" project-jdk-type="Python SDK" />
|
||||
</project>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/xumu_iot.iml" filepath="$PROJECT_DIR$/.idea/xumu_iot.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,237 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AutoImportSettings">
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="6fcbdb26-1795-4695-b353-57b405f1e401" name="Changes" comment="">
|
||||
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/lot_manager.iml" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/modules.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/api.py" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/bash/cron_delete_mp4.sh" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/bash/modify_device_name.sh" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/bash/record.sh" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/bash/start_data_upload.sh" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/bash/start_push_stream.sh" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/bash/stop_data_upload.sh" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/bash/stop_push_stream.sh" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/bash/stream.sh" beforeDir="false" afterPath="$PROJECT_DIR$/bash/stream.sh" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/close_blue_led.py" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/close_led.py" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/conf/common/data_upload.conf" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/conf/common/record.conf" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/conf/common/sensor_to_local.conf" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/conf/common/sensor_to_server.conf" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/conf/device/device.conf" beforeDir="false" afterPath="$PROJECT_DIR$/conf/device/device.conf" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/conf/example/bash/cron_set_for_32G.sh" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/conf/example/bash/cron_set_for_64G.sh" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/conf/example/bash/start_dataupload_internal_one_hour.sh" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/conf/example/bash/stop_dataupload_internal_one_hour.sh" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/conf/example/cron_for_32G.conf" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/conf/example/cron_for_64G.conf" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/conf/example/cron_for_dataupload.conf" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/conf/main/common.conf" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/conf/zhanguan/topic.conf" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/create_db.py" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/data_upload.py" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/db/__init__.py" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/db/base.py" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/db/models/__init__.py" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/db/models/base.py" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/db/models/lot_data_model.py" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/db/repository/__init__.py" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/db/repository/lot_data_repository.py" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/db/session.py" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/delete_lot_data_3_days.py" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/delete_than20G.py" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/install.sh" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/open_blue_led.py" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/open_led.py" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/requirements.txt" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/sensor_to_local.py" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/sensor_to_server.py" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/video_task.py" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/物联网系统程序开发流程.docx" beforeDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="FileTemplateManagerImpl">
|
||||
<option name="RECENT_TEMPLATES">
|
||||
<list>
|
||||
<option value="Python Script" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="HighlightingSettingsPerFile">
|
||||
<setting file="file://$USER_HOME$/anaconda3/envs/chatchat/lib/python3.10/site-packages/apscheduler/schedulers/base.py" root0="SKIP_INSPECTION" />
|
||||
<setting file="file://$USER_HOME$/anaconda3/envs/chatchat/lib/python3.10/threading.py" root0="SKIP_INSPECTION" />
|
||||
</component>
|
||||
<component name="MarkdownSettingsMigration">
|
||||
<option name="stateVersion" value="1" />
|
||||
</component>
|
||||
<component name="ProjectColorInfo">{
|
||||
"associatedIndex": 3
|
||||
}</component>
|
||||
<component name="ProjectId" id="2ZFroovnSrMb2c7rJ4bmA5cGRhH" />
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"git-widget-placeholder": "master",
|
||||
"last_opened_file_path": "/home/lihai/pythonProjects/xumu_iot/bash",
|
||||
"settings.editor.selected.configurable": "com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable"
|
||||
}
|
||||
}]]></component>
|
||||
<component name="RecentsManager">
|
||||
<key name="CopyFile.RECENT_KEYS">
|
||||
<recent name="$PROJECT_DIR$/bash" />
|
||||
<recent name="$PROJECT_DIR$" />
|
||||
<recent name="$PROJECT_DIR$/conf/example/bash" />
|
||||
<recent name="$PROJECT_DIR$/conf/example" />
|
||||
<recent name="$PROJECT_DIR$/conf/main" />
|
||||
</key>
|
||||
<key name="MoveFile.RECENT_KEYS">
|
||||
<recent name="$PROJECT_DIR$/conf/example/bash" />
|
||||
<recent name="$PROJECT_DIR$/bash" />
|
||||
<recent name="$PROJECT_DIR$/conf/device" />
|
||||
<recent name="$PROJECT_DIR$/conf/domain" />
|
||||
<recent name="$PROJECT_DIR$/conf" />
|
||||
</key>
|
||||
</component>
|
||||
<component name="RunManager" selected="Shell Script.git_push.sh">
|
||||
<configuration name="t" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
||||
<module name="xumu_iot" />
|
||||
<option name="INTERPRETER_OPTIONS" value="" />
|
||||
<option name="PARENT_ENVS" value="true" />
|
||||
<envs>
|
||||
<env name="PYTHONUNBUFFERED" value="1" />
|
||||
</envs>
|
||||
<option name="SDK_HOME" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||
<option name="IS_MODULE_SDK" value="true" />
|
||||
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/t.py" />
|
||||
<option name="PARAMETERS" value="" />
|
||||
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||
<option name="EMULATE_TERMINAL" value="false" />
|
||||
<option name="MODULE_MODE" value="false" />
|
||||
<option name="REDIRECT_INPUT" value="false" />
|
||||
<option name="INPUT_FILE" value="" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<configuration name="tes" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
||||
<module name="xumu_iot" />
|
||||
<option name="INTERPRETER_OPTIONS" value="" />
|
||||
<option name="PARENT_ENVS" value="true" />
|
||||
<envs>
|
||||
<env name="PYTHONUNBUFFERED" value="1" />
|
||||
</envs>
|
||||
<option name="SDK_HOME" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||
<option name="IS_MODULE_SDK" value="true" />
|
||||
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/tes.py" />
|
||||
<option name="PARAMETERS" value="" />
|
||||
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||
<option name="EMULATE_TERMINAL" value="false" />
|
||||
<option name="MODULE_MODE" value="false" />
|
||||
<option name="REDIRECT_INPUT" value="false" />
|
||||
<option name="INPUT_FILE" value="" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<configuration name="test" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
||||
<module name="xumu_iot" />
|
||||
<option name="INTERPRETER_OPTIONS" value="" />
|
||||
<option name="PARENT_ENVS" value="true" />
|
||||
<envs>
|
||||
<env name="PYTHONUNBUFFERED" value="1" />
|
||||
</envs>
|
||||
<option name="SDK_HOME" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||
<option name="IS_MODULE_SDK" value="true" />
|
||||
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/test.py" />
|
||||
<option name="PARAMETERS" value="" />
|
||||
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||
<option name="EMULATE_TERMINAL" value="false" />
|
||||
<option name="MODULE_MODE" value="false" />
|
||||
<option name="REDIRECT_INPUT" value="false" />
|
||||
<option name="INPUT_FILE" value="" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<configuration name="video_task" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
||||
<module name="xumu_iot" />
|
||||
<option name="INTERPRETER_OPTIONS" value="" />
|
||||
<option name="PARENT_ENVS" value="true" />
|
||||
<envs>
|
||||
<env name="PYTHONUNBUFFERED" value="1" />
|
||||
</envs>
|
||||
<option name="SDK_HOME" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||
<option name="IS_MODULE_SDK" value="true" />
|
||||
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/video_task.py" />
|
||||
<option name="PARAMETERS" value="" />
|
||||
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||
<option name="EMULATE_TERMINAL" value="false" />
|
||||
<option name="MODULE_MODE" value="false" />
|
||||
<option name="REDIRECT_INPUT" value="false" />
|
||||
<option name="INPUT_FILE" value="" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<configuration name="git_push.sh" type="ShConfigurationType" temporary="true">
|
||||
<option name="SCRIPT_TEXT" value="" />
|
||||
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
|
||||
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/git_push.sh" />
|
||||
<option name="SCRIPT_OPTIONS" value="" />
|
||||
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
|
||||
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
|
||||
<option name="INTERPRETER_PATH" value="/bin/bash" />
|
||||
<option name="INTERPRETER_OPTIONS" value="" />
|
||||
<option name="EXECUTE_IN_TERMINAL" value="true" />
|
||||
<option name="EXECUTE_SCRIPT_FILE" value="true" />
|
||||
<envs />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Shell Script.git_push.sh" />
|
||||
<item itemvalue="Python.test" />
|
||||
<item itemvalue="Python.video_task" />
|
||||
<item itemvalue="Python.t" />
|
||||
<item itemvalue="Python.tes" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="6fcbdb26-1795-4695-b353-57b405f1e401" name="Changes" comment="" />
|
||||
<created>1702028845497</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1702028845497</updated>
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="UnknownFeatures">
|
||||
<option featureType="com.intellij.fileTypeFactory" implementationName="*.conf" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="jdk" jdkName="agri_chatglm3" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="PyDocumentationSettings">
|
||||
<option name="format" value="PLAIN" />
|
||||
<option name="myDocStringFormat" value="Plain" />
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1,86 @@
|
|||
import time
|
||||
|
||||
import paho.mqtt.client as mqtt
|
||||
|
||||
from tool import *
|
||||
|
||||
from config import broker, port, subscribe_topic, username, password, info_topic
|
||||
|
||||
|
||||
def valid(msg, client):
|
||||
origin_data = json.loads(msg.payload.decode('utf-8'))
|
||||
if 'msg' not in origin_data:
|
||||
client.publish(info_topic, payload=publish_payload(code=404, msg="msg must be supplied"), qos=0)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
class MQTTClient:
|
||||
def __init__(self, broker, port, topic, username, password):
|
||||
self.broker = broker
|
||||
self.port = port
|
||||
self.topic = topic
|
||||
self.username = username
|
||||
self.password = password
|
||||
# 千万不要指定client_id 不然死翘翘
|
||||
self.client = mqtt.Client(client_id=subscribe_topic)
|
||||
self.client.username_pw_set(self.username, self.password)
|
||||
self.client.on_connect = self.on_connect
|
||||
self.client.on_message = self.on_message
|
||||
|
||||
def on_connect(self, client, userdata, flags, rc):
|
||||
if rc == 0:
|
||||
self.client.subscribe(self.topic)
|
||||
client.publish(info_topic, payload=publish_payload(code=200, msg='成功订阅' + self.topic),
|
||||
qos=0)
|
||||
# 关闭摄像机电
|
||||
subprocess.Popen(['sudo /usr/bin/python close_led.py'], shell=True)
|
||||
# 关闭LED灯
|
||||
subprocess.Popen(['sudo /usr/bin/python close_blue_led.py'], shell=True)
|
||||
|
||||
def on_message(self, client, userdata, msg):
|
||||
if not valid(msg, client):
|
||||
return
|
||||
try:
|
||||
origin_data = json.loads(msg.payload.decode('utf-8'))
|
||||
data = origin_data["msg"]
|
||||
if data == "push_stream":
|
||||
# 启动推流视频
|
||||
push_stream(client)
|
||||
elif data == "close_stream":
|
||||
# 关闭推流视频
|
||||
close_stream(client)
|
||||
elif data == "exec":
|
||||
# 执行命令
|
||||
exec_sh(msg, client)
|
||||
elif data == "update":
|
||||
# git更新项目和配置文件
|
||||
update(client)
|
||||
elif data == "reload":
|
||||
# 重启配置
|
||||
reload(client)
|
||||
elif data == "status":
|
||||
# 查看运行状态
|
||||
get_status(client)
|
||||
else:
|
||||
# 错误类型
|
||||
client.publish(info_topic, payload=publish_payload(code=404, msg='No Such Msg Type'), qos=0)
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
def start(self):
|
||||
self.client.connect(self.broker, self.port)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# MQTT客户端
|
||||
MQTT = MQTTClient(broker, port, subscribe_topic, username, password)
|
||||
# 循环连接
|
||||
while True:
|
||||
try:
|
||||
MQTT.start()
|
||||
# 阻塞监听
|
||||
MQTT.client.loop_forever()
|
||||
except Exception as e:
|
||||
# 异常等待时间在进行连接
|
||||
time.sleep(30)
|
|
@ -0,0 +1,2 @@
|
|||
#!/bin/bash
|
||||
supervisorctl start push_stream
|
|
@ -0,0 +1,2 @@
|
|||
#!/bin/bash
|
||||
supervisorctl stop push_stream
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
device_name=`cat /home/pi/device_name`
|
||||
/usr/bin/ffmpeg -rtsp_transport tcp -re -i "rtsp://admin:lihai123@192.168.0.123:554/cam/realmonitor?channel=1&subtype=0" -c copy -f rtsp -rtsp_transport tcp rtsp://47.108.186.87:554/live/$device_name
|
|
@ -0,0 +1,10 @@
|
|||
[program:__mqtt__]
|
||||
directory=/home/pi/lot_manager
|
||||
command=/usr/bin/python MQTT.py
|
||||
user=pi
|
||||
autostart=true
|
||||
autorestart=true
|
||||
redirect_stderr=true
|
||||
stopsignal=TERM
|
||||
stopasgroup=True
|
||||
priority=1
|
|
@ -0,0 +1,9 @@
|
|||
[program:push_stream]
|
||||
directory=/home/pi/lot_manager/bash
|
||||
command=/usr/bin/bash stream.sh
|
||||
user=pi
|
||||
autostart=true
|
||||
autorestart=true
|
||||
redirect_stderr=true
|
||||
stopsignal=TERM
|
||||
stopasgroup=True
|
|
@ -0,0 +1,10 @@
|
|||
# 设备1-32G
|
||||
# 编号
|
||||
[xumu_camera_1]
|
||||
# 订阅的控制主题,必须和系统设置的相同
|
||||
subscribe_topic=xumu_camera_1
|
||||
# 发布消息的主题
|
||||
publish_topic=camera_1
|
||||
info_topic=info_xumu_camera_1
|
||||
username=lihai_lot_land1
|
||||
password=lihai_lot_land1
|
|
@ -0,0 +1,40 @@
|
|||
; supervisor config file
|
||||
|
||||
[unix_http_server]
|
||||
file=/var/run/supervisor.sock ; (the path to the socket file)
|
||||
chmod=0777 ; sockef file mode (default 0700)
|
||||
|
||||
[supervisord]
|
||||
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
|
||||
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
|
||||
childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP)
|
||||
user=root
|
||||
; the below section must remain in the config file for RPC
|
||||
; (supervisorctl/web interface) to work, additional interfaces may be
|
||||
; added by defining them in separate rpcinterface: sections
|
||||
[rpcinterface:supervisor]
|
||||
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
|
||||
|
||||
[supervisorctl]
|
||||
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket
|
||||
user=pi
|
||||
; The [include] section can just contain the "files" setting. This
|
||||
; setting can list multiple files (separated by whitespace or
|
||||
; newlines). It can also contain wildcards. The filenames are
|
||||
; interpreted as relative to this file. Included files *cannot*
|
||||
; include files themselves.
|
||||
[inet_http_server]
|
||||
host = 127.0.0.1
|
||||
port = 9001
|
||||
[program:__mqtt__]
|
||||
directory=/home/pi/lot_manager
|
||||
command=/usr/bin/python MQTT.py
|
||||
user=pi
|
||||
autostart=true
|
||||
autorestart=true
|
||||
redirect_stderr=true
|
||||
stopsignal=TERM
|
||||
stopasgroup=True
|
||||
priority=1
|
||||
[include]
|
||||
files = /home/pi/lot_manager/conf/common/*.conf
|
|
@ -0,0 +1 @@
|
|||
xumu_camera_1
|
|
@ -0,0 +1,44 @@
|
|||
import configparser
|
||||
|
||||
import subprocess
|
||||
|
||||
try:
|
||||
p = subprocess.Popen(['cat /home/pi/device_name'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
out, err = p.communicate()
|
||||
# 设备名称,必须要有
|
||||
device_name = out.decode('utf-8').strip()
|
||||
|
||||
# 读取配置
|
||||
config = configparser.ConfigParser()
|
||||
# 读取公共配置
|
||||
config.read('conf/main/common.conf')
|
||||
# 域名
|
||||
broker = config.get("broker", "host")
|
||||
# 端口,这里必须是int类型
|
||||
port = config.getint("broker", "port")
|
||||
# 录像地址
|
||||
post_record_list_url = config.get("record", "post_record_list_url")
|
||||
post_record_url = config.get("record", "post_record_url")
|
||||
|
||||
# 读取设备配置
|
||||
config.read('conf/device/device.conf')
|
||||
# 订阅的主题
|
||||
subscribe_topic = config.get(device_name, "subscribe_topic")
|
||||
# 发布数据的主题
|
||||
publish_topic = config.get(device_name, "publish_topic")
|
||||
# 发布信息的主题
|
||||
info_topic = config.get(device_name, "info_topic")
|
||||
# 用户
|
||||
username = config.get(device_name, "username")
|
||||
# 密码
|
||||
password = config.get(device_name, "password")
|
||||
|
||||
# 特殊配置
|
||||
config.read('conf/zhanguan/topic.conf')
|
||||
zhanguan_device_name = config.get("device", "name")
|
||||
|
||||
# tool配置
|
||||
mp4_path = '/home/pi/mp4'
|
||||
except Exception as e:
|
||||
# print(e)
|
||||
pass
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
git add .
|
||||
git commit -m 'update'
|
||||
git push -f origin master
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
# git更新
|
||||
git pull origin master --force
|
||||
# 配置文件复制到supervisor管理
|
||||
# cp -r conf/common/*.conf /etc/supervisor/conf.d/
|
||||
# 更新配置文件
|
||||
supervisorctl reread
|
||||
supervisorctl update
|
|
@ -0,0 +1,2 @@
|
|||
paho-mqtt~=1.6.1
|
||||
requests~=2.31.0
|
|
@ -0,0 +1,92 @@
|
|||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import threading
|
||||
|
||||
import requests
|
||||
|
||||
from config import mp4_path, post_record_list_url, post_record_url, info_topic
|
||||
|
||||
|
||||
# 统一返回
|
||||
def publish_payload(code, msg):
|
||||
return json.dumps({
|
||||
"code": code,
|
||||
"msg": msg
|
||||
}, ensure_ascii=False)
|
||||
|
||||
|
||||
def exception_handler(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except Exception as e:
|
||||
print(f"函数{func.__name__}中发生了异常:{e}")
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
def push_stream(client):
|
||||
p = subprocess.Popen(['/bin/bash /home/pi/lot_manager/bash/start_push_stream.sh'],
|
||||
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(200, output), qos=0)
|
||||
|
||||
|
||||
def close_stream(client):
|
||||
p = subprocess.Popen(['/bin/bash /home/pi/lot_manager/bash/stop_push_stream.sh'],
|
||||
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=output), qos=0)
|
||||
|
||||
|
||||
def exec_sh(msg, client):
|
||||
origin_data = json.loads(msg.payload.decode('utf-8'))
|
||||
if 'data' not in origin_data:
|
||||
client.publish(info_topic, payload=publish_payload(code=404, msg='data must be supplied'), qos=0)
|
||||
return
|
||||
cmd = origin_data["data"]
|
||||
if cmd in ["supervisorctl stop __mqtt__",
|
||||
"supervisorctl restart __mqtt__",
|
||||
"supervisorctl stop all"]:
|
||||
return
|
||||
if cmd == "supervisorctl reload":
|
||||
client.publish(info_topic, payload=publish_payload(code=200, msg='reloading'), qos=0)
|
||||
subprocess.Popen([cmd], shell=True)
|
||||
return
|
||||
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=output), qos=0)
|
||||
|
||||
|
||||
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').strip()
|
||||
client.publish(info_topic, payload=publish_payload(code=200, msg=output), qos=0)
|
||||
|
||||
|
||||
def update(client):
|
||||
p = subprocess.Popen(['/bin/bash /home/pi/lot_manager/git_update.sh'],
|
||||
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=output),
|
||||
qos=0)
|
||||
|
||||
|
||||
def reload(client):
|
||||
client.publish(info_topic, payload=publish_payload(200, "reloading"), qos=0)
|
||||
subprocess.Popen(['supervisorctl reload'], shell=True)
|
Loading…
Reference in New Issue