當前位置:博客首頁(yè)>>樹(shù)莓派 >> 閱讀正文

樹(shù)莓派安裝homebridge小記

作者: 鄭曉 分類(lèi): 樹(shù)莓派 發(fā)布于: 2018-08-02 08:35 瀏覽:87,875 評論(3)


樹(shù)莓派3B+ 系統Raspbian

設置國內源

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo vi /etc/apt/sources.list
# 這里從網(wǎng)上找國內源復制進(jìn)文件中保存

安裝homebridge

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

# 升級node 因為安裝yeelight插件時(shí)有限制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
# 以下網(wǎng)上搜的命令最后是mdns 但我并沒(méi)有這個(gè)目錄,我從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

# 安裝完成 執行以下代碼運行測試 會(huì )生成二維碼 使用iOS上的家庭,添加設備,掃碼完成添加。
/usr/local/bin/homebridge

配置homebridge的自啟動(dòng)

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
# 完成 使用以下命令可啟動(dòng)服務(wù),斷電開(kāi)機時(shí)也會(huì )自動(dòng)啟動(dòng)
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

? ? ? ?

本文采用知識共享署名-非商業(yè)性使用 3.0 中國大陸許可協(xié)議進(jìn)行許可,轉載時(shí)請注明出處及相應鏈接。

本文永久鏈接: http://www.gdmymj.com/raspberry-homebridge.html

樹(shù)莓派安裝homebridge小記:目前有3 條留言

用戶(hù)評論頭像 丁八塊發(fā)表于 2018年11月12日 15:33[回復]

我是來(lái)試試名字的

用戶(hù)評論頭像 ljx發(fā)表于 2018年08月09日 09:10[回復]

樓主用的是什么富文本編輯器呢,看起來(lái)縮進(jìn)上對代碼的支持不太好

用戶(hù)評論頭像 php讀取word求助發(fā)表于 2018年08月02日 15:00[回復]

博主,你好!php讀取word求助,按照這個(gè)教程antiword-read-word-doc.html,讀取出來(lái)的word是純文本的,能否保留原排版格式 呢

發(fā)表評論

change vcode