通过iPhone的siri控制卧室灯的开关,这是在2017年玩过的,现在翻出来分享一下。
所需设备
- 一部苹果手机(可以使用siri)
- 一个yeelight灯泡(可以接入家庭wifi联网)
- 树莓派(微型后台服务器)
系统搭建
- iPhone、灯泡、树莓派都要接入家里的网络,确保设备处于同一局域网下
-
树莓派需烧录homebridge程序(方法在下面会讲到),然后通过iPhone将灯泡添加到homekit中
homekit(自己的图太久了没找到,从网上找了一张)
树莓派配置homebridge
这个程序是17年发布在我的CSDN博客中的,现在搬过来。
树莓派版本:raspberry pi2
树莓派配合homebridge实现iphone HomeKit siri控制树莓派gpio
更新源
sudo apt-get update
sudo apt-get upgrade
安装c++11 or later
sudo vim /etc/apt/sources.list
// ___replace jessie with wheezy
#deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi
deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi
sudo apt-get update
sudo apt-get install gcc-4.9 g++-4.9
sudo vim /etc/apt/sources.list
// ___replace wheezy with jessie
deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi
#deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi
sudo apt-get update
export CC=/usr/bin/gcc-4.9
export CXX=/usr/bin/g++-4.9
如果不安装c++11,后面npm安装homebridge将报以下错误:
Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/usr/local/lib/node_modules/node-inspector/node_modules/v8-profiler/build/profiler/v5.3.0/node-v46-linux-arm/profiler.node --module_name=profiler --module_path=/usr/local/lib/node_modules/node-inspector/node_modules/v8-profiler/build/profiler/v5.3.0/node-v46-linux-arm' (1)
npm ERR! Linux 4.1.6+
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "-g" "install" "node-inspector"
npm ERR! node v4.0.0
npm ERR! npm v2.14.2
npm ERR! code ELIFECYCLE
npm ERR! v8-debug@0.5.3 install: node-pre-gyp install --fallback-to-build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the v8-debug@0.5.3 install script 'node-pre-gyp install --fallback-to-build'.
npm ERR! This is most likely a problem with the v8-debug package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-pre-gyp install --fallback-to-build
npm ERR! You can get their info via:
npm ERR! npm owner ls v8-debug
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/jnavratil/npm-debug.log
安装nodejs
wget https://nodejs.org/dist/v4.0.0/node-v4.0.0-linux-armv7l.tar.gz
tar -xvf node-v4.0.0-linux-armv7l.tar.gz
cd node-v4.0.0-linux-armv7l
sudo cp -R * /usr/local/
// 检查是否安装成功
node -v
// Install Avahi and other Dependencies
sudo apt-get install libavahi-compat-libdnssd-dev
安装homebridge插件
sudo npm install homebridge-gpio-wpi2
npm安装gpio插件
npm install -g homebridge-gpio
编写config文件
sudo vim /home/pi/.homebridge/config.json
{
"bridge": {
"name": "Homebridge",
"username": "CC:22:3D:E3:CE:30",
"port": 51826,
"pin": "133-45-678"
},
"platforms": [{
"platform" : "WiringPiPlatform",
"name" : "Pi GPIO (WiringPi)",
"overrideCache" : "true",
"autoExport" : "true",
"gpiopins" : [{
"name" : "灯",
"pin" : 27,
"enabled" : "true",
"mode" : "out",
"pull" : "down",
"inverted" : "false",
"duration" : 0,
"polling" : "true"
},{
"name" : "门",
"pin" : 22,
"enabled" : "true",
"mode" : "in",
"pull" : "off",
"inverted" : "false",
"duration" : 0
}]
}]
}
// :wq 保存退出
// 打开homebridge
$ homebridge
来把玩你的新玩具吧
现在可以掏出iPhone手机,呼出siri,像下面这样指挥它来开关你的室内灯了。
抖音是最近发的图片源自网络,侵权必删!
参考:
原始博客地址:树莓派安装homebridge
Running Homebridge on a Raspberry Pi
Raspberry Pi 2 : gyp ERR! build error (zmq)
homebridge
Installing Node.js v4.0.0 on a Raspberry Pi (All Models)
homebridge-gpio
HomeKit初体验
树莓派安装homekit
网友评论