安装系统
格式sd卡
下载最新lite版系统,写系统到sd卡
boot磁盘新建ssh空文件
连接网线
路由器查看ip
ssh pi@ip 密码:raspberry
配置wifi: sudo raspi-config
修改root密码: "echo root:123456" | chpasswd
技巧
问题
npm慢
npm --registry https://registry.npm.taobao.org info underscore
pip安装 python库慢
- 使用
sudo apt-get install python-numpy
,sudo apt-get install python-pygame
安装 - 可以使用这样的安装命令
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy
这样就可以从清华大学的镜像很快去安装库了。 - 将pip的源换为国内的。
1.新建目录及文件~/.pip/pip.conf
2.内容为:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com
蓝牙操作,使用蓝牙当做A2DPsink端播放音乐
sudo apt-get install bluetooth bluez blueman
sudo apt-get install libbluetooth-dev
sudo apt-get install pulseaudio pulseaudio-module-bluetooth
sudo vi /lib/systemd/system/bluetooth.service
# 在这一句后面加上一个-C ExecStart=/usr/lib/bluetooth/bluetoothd -C
# 让服务随系统启动
sudo systemctl enable bluetooth
sudo systemctl restart bluetooth
sudo systemctl status bluetooth
image.png
通过shairport 做无线音箱
tmux 后台播放musicbox
使用修改好带启动播放参数的musicbox:https://github.com/cloudswave/musicbox
tmux new-session -d -s musicbox musicbox -c "?"
web shell
sudo apt-get install shellinabox
# shellinabox
sudo apt-get install shellinabox
cat /etc/default/shellinabox #查看端口 https://*****:4200
#sudo service shellinabox restart #启动服务
shellinaboxd -b -t -p 4200
#-b #后台运行
#-u #运行用户,默认nobody
#-g #运行用户组
#-p #监听端口,默认4200
#-t #不以ssl运行
#-c #证书目录
开机启动应用
/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
bash /home/pi/startup.sh
exit 0
/home/pi/startup.sh
#!/bin/bash
LOG_FILE="/home/pi/boot.log"
function logit()
{
echo "[${USER}][`date`] - ${*}" >> ${LOG_FILE}
}
cd /home/pi
# koe
logit "kode start"
/etc/init.d/php7.0-fpm restart &
/etc/init.d/nginx restart &
# node
logit "node start"
forever start -w ./pi3-script/node_web/app.js
# nas
logit "samba restart"
/etc/init.d/samba restart &
# web shell
#shellinaboxd -b -t -p 4200
#挂载U
#./mount-usb.sh
#wifi助手
logit "raspberry_pi_helper start"
sudo nohup ./raspberry_pi_helper/start_pihelper.py &
# 智能家居助手
nohup ./homeassistant/bin/hass -c "/home/pi/.homeassistant" >> /dev/null &
# 叮当语音
#echo ...启动叮当语音.. >> ./startup.log
#sh /home/pi/dingdang/launcher/dingdang-launcher-user.sh
# shairplay
#nohup shairplay -a pi >> /dev/null &
./shairport/shairport -a pi -d
# frpc
sleep 3
logit "frpc start"
nohup ./bin/frpc >> /dev/null &
自动挂载
#安装所需软件包
sudo apt-get install ntfs-3g
#加载内核模块
sudo modprobe fuse
mkdir /home/pi/share/my_usb
sudo mount /dev/sda1 /home/pi/share/my_usb -w
#sudo umount /home/pi/share/my_usb
sudo echo /dev/sda1 /home/pi/share/my_usb auto defaults,noexec,umask=0000 0 0 >> /etc/fstab
motion实现输出视频文件家庭监控
我采用的是这个方法,因为motion这个开源软件配置好之后,实在是非常好用。
首先安装motion
sudo apt-get install motion
接着对/etc/motion/motion.conf进行编辑
sudo vi /etc/motion/motion.conf
修改以下相应参数
daemon off //后台运行关闭,如果你需要24小时监控,可以设置为开启
stream_localhost off //此处修改为off,否则无法登陆默认8081端口的监控页面
webcontrol_localhost off //此处修改为off,否则无法登陆默认8080端口的配置页面
quiet on
videodevice /dev/video0
width 320
height 240
framerate 2
auto_brightness off
target_dir /mnt/disk //默认保存位置需要修改,否则运行出错
output_pictures off //因为我不需要输出图片保存,因此此项关闭
ffmpeg_output_movies on //输出视频
设置好之后执行
sudo motion
监控开始工作,当有侦测到有运动状态时,就会自动以视频形式记录,如果监控画面长时间没有变化,则停止记录。
此外motion.conf中还有on_event_start和on_event_end设置,这两个参数分别用于当检测到运行状态时,开始记录时执行的脚本,以及当停止记录时执行的脚本,通过编写脚本,可以实现一旦监控到内容即时发送视频到指定邮箱这样的功能,具体实现可以 参考这里 。
其他
- 查看开机log:
cat /var/log/boot.log
- 自动挂载:
sudo apt-get install usbmount
- 基于Python3的开源网络视频下载工具 you-get下载器:
pip3 install you-get
, gui:https://github.com/ingbyr/VDM, https://linux.cn/article-9678-1.html