SIYI 热插拔系统
最终稳定版 · Jetson 以太网相机自动识别与配置
MAC 地址检测 静态 IP 自动分配 即插即用 无启动挂起风险 自动启动相机流水线
系统功能概述
通过 MAC 地址自动检测 SIYI 以太网相机
安全拉起网络接口(不阻塞启动)
分配静态 IP:192.168.144.2/24
验证与相机 (192.168.144.25) 的连通性
可选自动启动相机流水线
在 Jetson 完全启动后工作,零启动挂起风险
安全拉起网络接口(不阻塞启动)
分配静态 IP:192.168.144.2/24
验证与相机 (192.168.144.25) 的连通性
可选自动启动相机流水线
在 Jetson 完全启动后工作,零启动挂起风险
第一步:获取相机 MAC 地址
ip a | grep -A 2 "enx"
示例输出中记录类似 00:e0:4c:68:0a:4c 的 MAC 地址(注意替换脚本中的 MAC 值)
执行
ip -o link | grep enx 可快速列出所有 USB 以太网接口及其 MAC。 第二步:创建主脚本
sudo nano /usr/local/bin/siyi_hotplug.sh
脚本完整内容
#!/bin/bash
# =========================
# SIYI HOTPLUG MANAGER (v2 stable)
# =========================
MAC="00:e0:4c:68:0a:4c" # 替换为你的相机 MAC
IP="192.168.144.2"
NETMASK="255.255.255.0"
CAM_IP="192.168.144.25"
CAM_DIR="/home/nvidia/siyi_cam"
configured=0
echo "[SIYI] Hotplug service started..."
echo "[SIYI] Waiting for camera..."
while true; do
# 通过 MAC 查找接口(安全匹配)
IFACE=$(ip -o link | awk -v mac="$MAC" '
tolower($0) ~ tolower(mac) {print $2}
' | sed 's/://')
if [ -n "$IFACE" ]; then
# 每个检测周期只配置一次
if [ "$configured" -eq 0 ]; then
echo "[SIYI] Detected interface: $IFACE"
ip link set "$IFACE" up
ifconfig "$IFACE" $IP netmask $NETMASK up
echo "[SIYI] Network configured:"
ip a show "$IFACE"
echo "[SIYI] Testing connection..."
if ping -c 2 $CAM_IP > /dev/null 2>&1; then
echo "[SIYI] Camera online "
if [ -d "$CAM_DIR" ]; then
echo "[SIYI] Starting camera pipeline..."
cd "$CAM_DIR"
nohup python3 capture_mkv.py > cam.log 2>&1 &
fi
configured=1
else
echo "[SIYI] Camera not responding yet..."
fi
fi
else
# 网线拔掉时重置状态
if [ "$configured" -eq 1 ]; then
echo "[SIYI] Camera disconnected"
configured=0
fi
fi
sleep 2
done
sudo chmod +x /usr/local/bin/siyi_hotplug.sh
请将
MAC 变量替换为你相机的实际 MAC 地址,CAM_DIR 改为你的相机流水线脚本所在目录。 第三步:创建 Systemd 服务(开机自启 + 热插拔)
sudo nano /etc/systemd/system/siyi-hotplug.service
[Unit]
Description=SIYI Hotplug Manager
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/local/bin/siyi_hotplug.sh
Restart=always
RestartSec=3
User=root
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable siyi-hotplug.service
sudo systemctl start siyi-hotplug.service
服务将随系统启动,并在意外退出时自动重启(每 3 秒)。
服务管理命令
| 操作 | 命令 |
|---|---|
| 查看状态 | sudo systemctl status siyi-hotplug |
| 停止服务 | sudo systemctl stop siyi-hotplug |
| 重启服务 | sudo systemctl restart siyi-hotplug |
| 查看实时日志 | sudo journalctl -u siyi-hotplug -f |
| 查看最近 50 行日志 | sudo journalctl -u siyi-hotplug -n 50 |
故障排查
相机未被检测到
ip -o link | grep enx # 检查是否有 enx 接口出现
ip a show enx... # 查看接口是否 UP
ping 192.168.144.25 # 测试相机连通性
脚本无输出 / 服务未运行
sudo systemctl status siyi-hotplug
sudo journalctl -u siyi-hotplug -f --no-pager
确保脚本具有可执行权限 (
chmod +x),且 Systemd 服务文件路径正确。 自定义相机流水线
# 修改脚本中的 CAM_DIR 和启动命令即可
CAM_DIR="/home/nvidia/siyi_cam"...
nohup python3 capture_mkv.py > cam.log 2>&1 &
你可以替换为任意的 RTSP 拉流、视频录制或 AI 推理脚本(需保持前台/后台不阻塞主循环)。
系统工作流
[SIYI] Hotplug service started...
[SIYI] Waiting for camera...
[SIYI] Detected interface: enx00e04c680a1f
[SIYI] Network configured: 192.168.144.2
[SIYI] Testing connection...
[SIYI] Camera online
[SIYI] Starting camera pipeline...
从此相机即插即用,无需人工干预,Jetson 永远可以正常启动。