IT学习网 - 爱学习 - 最具影响力综合资讯网站 -- 中国IT界的领航者!
热门关键字:      88888  as  xxx
站外
广告
站外
广告

极客DIY:如何用Siri与树莓派“交互”

发布时间:2016-11-16 17:28文章来源:互联网文章作者: 互联网点击次数:
苹果在2014年推出的HomeKit智能家居平台的确给人眼前一亮的感觉。随着时间的推移,国外的黑客对HomeKit该逆向的逆向,结果也都汇总到了git。本着折腾到死的极客心态,从网上淘了一块树莓派进行测试。 001 基本工具 硬件在某宝上都有卖的,加起来不到300块 硬
苹果在2014年推出的HomeKit智能家居平台的确给人眼前一亮的感觉。随着时间的推移,国外的黑客对HomeKit该逆向的逆向,结果也都汇总到了git。本着折腾到死的极客心态,从网上淘了一块树莓派进行测试。

0×01 基本工具

硬件在某宝上都有卖的,加起来不到300块
硬件:
32G SD卡
2.5V电源线
Raspberry pi3
两根杜邦线
LED灯
保护壳
联动HomeKit的工程在git上找到两个,都是基于nodejs的,这边先测试的是HAP-NodeJS
软件
raspbian
https://github.com/nfarina/homebridge
https://github.com/KhaosT/HAP-NodeJS

0×02 安装

先解决依赖 # apt-get install avahi-daemon avahi-discover libnss-mdns libavahi-compat-libdnssd-dev build-essential -y # service avahi-daemon start
增加nodejs源 curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
1.png # apt-get install nodejs 2.png 克隆源代码 git clone https://github.com/KhaosT/HAP-NodeJS.git
安装node-gyp $ sudo npm install -g node-gyp
3.png 然后切换到HAP-NodeJS文件夹下,运行 node Core,js 缺哪个库安装哪个库 5.png 最后安装 npm install python-shell 6.png 打开iPhone手机的HomeKit就能看到伪造的智能设备了 IMG_0085.PNG 在accessories的目录下新建一个LivingLight_accessory.js,代码如下 //Light_accessory.js var PythonShell = require('python-shell'); // HomeKit types required var types = require("./types.js") var exports = module.exports = {}; var execute = function(accessory,characteristic,value){ console.log("executed accessory: " + accessory + ", and characteristic: " + characteristic + ", with value: " + value + "."); } exports.accessory = { displayName: "Living Light", username: "1A:5B:3C:4A:5E:FF", pincode: "031-45-154", services: [{ sType: types.ACCESSORY_INFORMATION_STYPE, characteristics: [{ cType: types.NAME_CTYPE, onUpdate: null, perms: ["pr"], format: "string", initialValue: "Living Light", supportEvents: false, supportBonjour: false, manfDescription: "Bla", designedMaxLength: 255 },{ cType: types.MANUFACTURER_CTYPE, onUpdate: null, perms: ["pr"], format: "string", initialValue: "Oltica", supportEvents: false, supportBonjour: false, manfDescription: "Bla", designedMaxLength: 255 },{ cType: types.MODEL_CTYPE, onUpdate: null, perms: ["pr"], format: "string", initialValue: "Rev-1", supportEvents: false, supportBonjour: false, manfDescription: "Bla", designedMaxLength: 255 },{ cType: types.SERIAL_NUMBER_CTYPE, onUpdate: null, perms: ["pr"], format: "string", initialValue: "A1S2NASF88EW", supportEvents: false, supportBonjour: false, manfDescription: "Bla", designedMaxLength: 255 },{ cType: types.IDENTIFY_CTYPE, onUpdate: null, perms: ["pw"], format: "bool", initialValue: false, supportEvents: false, supportBonjour: false, manfDescription: "Identify Accessory", designedMaxLength: 1 }] },{ sType: types.LIGHTBULB_STYPE, characteristics: [{ cType: types.NAME_CTYPE, onUpdate: null, perms: ["pr"], format: "string", initialValue: "Light 1 Light Service", supportEvents: false, supportBonjour: false, manfDescription: "Bla", designedMaxLength: 255 },{ cType: types.POWER_STATE_CTYPE, onUpdate: function(value) { console.log("Change:",value); if (value) { PythonShell.run('/python/light1.py', function (err) { console.log('Light1 On Success'); }); } else { PythonShell.run('/python/light0.py', function (err) { console.log("Off Success"); }); } }, perms: ["pw","pr","ev"], format: "bool", initialValue: false, supportEvents: false, supportBonjour: false, manfDescription: "Turn On the Light", designedMaxLength: 1 },{ cType: types.HUE_CTYPE, onUpdate: function(value) { console.log("Change:",value); execute("Test Accessory 1", "Light - Hue", value); }, perms: ["pw","pr","ev"], format: "int", initialValue: 0, supportEvents: false, supportBonjour: false, manfDescription: "Doesn’t actually adjust Hue of Light", designedMinValue: 0, designedMaxValue: 360, designedMinStep: 1, unit: "arcdegrees" },{ cType: types.BRIGHTNESS_CTYPE, onUpdate: function(value) { console.log("Change:",value); execute("Test Accessory 1", "Light - Brightness", value); }, perms: ["pw","pr","ev"], format: "int", initialValue: 0, supportEvents: false, supportBonjour: false, manfDescription: "Doesn’t actually adjust Brightness of Light", designedMinValue: 0, designedMaxValue: 100, designedMinStep: 1, unit: "%" },{ cType: types.SATURATION_CTYPE, onUpdate: function(value) { console.log("Change:",value); execute("Test Accessory 1", "Light - Saturation", value); }, perms: ["pw","pr","ev"], format: "int", initialValue: 0, supportEvents: false, supportBonjour: false, manfDescription: "Doesn’t actually adjust Saturation of Light", designedMinValue: 0, designedMaxValue: 100, designedMinStep: 1, unit: "%" }] }] }
极客DIY:如何用Siri与树莓派“交互”
本文由 IT学习网 整理,转载请注明“转自IT学习网”,并附上链接。
原文链接:http://www.ourlove520.com/Article/diannao/xitong/553164.html

标签分类:

上一篇:上一篇:极客DIY:制作一个可以面部、自主规划路径及语音识别的无人机
下一篇: 下一篇:没有了
无觅关联推荐,快速提升流量