树莓派安装homebridge小记

树莓派3B+ 系统Raspbian

设置国内源

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo vi /etc/apt/sources.list
# 这里从网上找国内源复制进文件中保存

安装homebridge

sudo apt-get update
sudo apt-get install npm
sudo npm install -g n
sudo n stable

# 升级node 因为安装yeelight插件时有限制node版本
sudo apt-get install libavahi-compat-libdnssd-dev

sudo npm install -g --unsafe-perm homebridge hap-nodejs node-gyp
cd /usr/local/lib/node_modules/homebridge/
sudo npm install --unsafe-perm bignum
# 以下网上搜的命令最后是mdns 但我并没有这个目录,我从ed25519-hap目录中找到了同样的gyp文件
cd /usr/local/lib/node_modules/hap-nodejs/node_modules/ed25519-hap/
sudo node-gyp BUILDTYPE=Release rebuild
sudo npm install -g homebridge-yeelight

# 安装完成 执行以下代码运行测试 会生成二维码 使用iOS上的家庭,添加设备,扫码完成添加。
/usr/local/bin/homebridge

配置homebridge的自启动

sudo vi /etc/init.d/homebridge

添加以下代码

#!/bin/sh
dir="/home/pi"
cmd="DEBUG=* /usr/local/bin/homebridge"
user="pi"

name=`basename $0`
pid_file="/var/run/$name.pid"
stdout_log="/var/log/$name.log"
stderr_log="/var/log/$name.err"

get_pid() {
cat "$pid_file"
}

is_running() {
[ -f "$pid_file" ] && ps -p `get_pid` > /dev/null 2>&1
}

case "$1" in
start)
if is_running; then
echo "Already started"
else
echo "Starting $name"
cd "$dir"
if [ -z "$user" ]; then
sudo $cmd >> "$stdout_log" 2>> "$stderr_log" &
else
sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log" &
fi
echo $! > "$pid_file"
if ! is_running; then
echo "Unable to start, see $stdout_log and $stderr_log"
exit 1
fi
fi
;;
stop)
if is_running; then
echo -n "Stopping $name.."
kill `get_pid`
for i in 1 2 3 4 5 6 7 8 9 10
# for i in `seq 10`
do
if ! is_running; then
break
fi

echo -n "."
sleep 1
done
echo
if is_running; then
echo "Not stopped; may still be shutting down or shutdown may have failed"
exit 1
else
echo "Stopped"
if [ -f "$pid_file" ]; then
rm "$pid_file"
fi
fi
else
echo "Not running"
fi
;;
restart)
$0 stop
if is_running; then
echo "Unable to stop, will not attempt to start"
exit 1
fi
$0 start
;;
status)
if is_running; then
echo "Running"
else
echo "Stopped"
exit 1
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0

最后

sudo chmod 755 /etc/init.d/homebridge
sudo update-rc.d homebridge defaults
# 完成 使用以下命令可启动服务,断电开机时也会自动启动
sudo /etc/init.d/homebridge start

————————-
期间的history记录

108 node
109 sudo apt-get install libavahi-compat-libdnssd-dev
110 sudo npm install -g homebridge-yeelight
111 sudo apt-get install npm
112 sudo vi /etc/apt/sources.list
113 sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
114 sudo vi /etc/apt/sources.list
115 sudo apt-get install npm
116 sudo apt-get update
117 sudo apt-get install npm
118 sudo npm install -g homebridge-yeelight
119 n -V
120 sudo npm install -g n
121 n -V
122 sudo n -V
123 sudo n stable
124 sudo apt-get install libavahi-compat-libdnssd-dev
125 sudo npm install -g homebridge-yeelight
126 ls -a
127 homebridge
128 sudo npm install -g --unsafe-perm homebridge hap-nodejs node-gyp
129 cd /usr/local/lib/node_modules/homebridge/
130 sudo npm install --unsafe-perm bignum
131 cd /usr/local/lib/node_modules/hap-nodejs/node_modules/mdns
132 cd /usr/local/lib/node_modules/hap-nodejs/node_modules/multicast-dns
133 ls
134 cd ..
135 sudo node-gyp
136 sudo node-gyp BUILDTYPE=Release rebuild
137 sudo npm install -g homebridge-yeelight
138 cd /usr/local/lib/node_modules/hap-nodejs/node_modules/ed25519-hap/
139 ls
140 sudo node-gyp BUILDTYPE=Release rebuild
141 /usr/local/bin/homebridge
142 exit
143 sudo vi /etc/init.d/homebridge
144 sudo chmod 755 /etc/init.d/homebridge
145 sudo update-rc.d homebridge defaults
146 sudo vi /etc/init.d/homebridge
147 sudo update-rc.d homebridge defaults
148 sudo /etc/init.d/homebridge start
149 sudo reboot
150 history

本文链接:https://my.lmcjl.com/post/14.html

展开阅读全文

4 评论

留下您的评论.