树莓派安装homebridge

树莓派版本: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! [email protected] install: node-pre-gyp install –fallback-to-build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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

参考:

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

你可能感兴趣的:(智能家居,raspberry,pi,siri,iphone)