便携式ROV搭建系列(四):树莓派开机自启动
1 视频传输方案
开源项目:mjpeg-streamer
1.1 启动脚本文件
在home/pi/mjpeg-streamer-master/mjpeg-streamer-experimental/路径下新建一个 CameraStart.sh文件,文件内容如下:
#!/bin/sh
cd /home/pi/mjpg-streamer-master/mjpg-streamer-experimental
./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so -w ./www"
1.2 /etc/rc.local
输入命令
sudo nano /etc/rc.local
修改后:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
# 修改的地方
/home/pi/mjpg-streamer-master/mjpg-streamer-experimental/cameraStart.sh start
exit 0
2 通信自启动方案
1.1 桌面程序自启动
在/home/pi/.config下创建一个名为autostart的文件夹
在该文件夹下创建一个communication.desktop文件,文件内容如下:
[Desktop Entry]
Name=communication
Exec=python /home/pi/communication.py
Terminal=true
Type=Application
StartupNotify=true
但牵扯到socket通信,该方式启动成功存在一定的概率,并不是每次都能启动,因此还是通过 /etc/rc.local文件启动。
1.2 最终程序
两个自启动程序都通过 /etc/rc.local 完成
1.2.1 新建communicationStart.sh脚本文件
在home/pi/mjpeg-streamer-master/mjpeg-streamer-experimental/路径下新建一个 communicationStart.sh文件,文件内容如下:
#!/bin/bash
python /home/pi/commnication.py
即在该目录下有两个 .sh 脚本文件
1.2.2 修改cameraStart.sh脚本文件
#!/bin/sh
cd /home/pi/mjpg-streamer-master/mjpg-streamer-experimental
./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so -w ./www"
./communicationStart.sh
注意:脚本文件更改后要重新更改权限
chmod 777 cameraStart.sh
重启即可
sudo reboot