Arduino ESP8266 模拟 Philips Hue 智能灯设备

在上一个玩法《智能家居声控:Amazon Echo + NodeMCU(ESP8266 模拟 Wemo)控制 LED》中,我尝试使用 ESP8266 模拟了 Wemo 设备,以此来使用 Amazon Echo 设备来控制。于是,便想着是否能通过 ESP8266 来仿真 Philips Hue 设备,来实现同样的效果。

遗憾的是,Philips Hue 设备与 Amazon Echo 通讯需要帐户登录,因此便放弃了想法。尽管如此,还是记录一下 ESP8266 模拟 Philips Hue 设备的过程。。

这一篇里,我们所需要的设备只有一个ESP8266

步骤1:环境准备

首先,我们需要安装 Arduino ESP8266,请参考上一篇文章:《智能家居声控:Amazon Echo + NodeMCU(ESP8266 模拟 Wemo)控制 LED》。

为了实现上面的目的,我们需要用到 ESP8266 Hue Emulator 项目,其 GitHub 地址:ESP8266HueEmulator

而这个 ESP8266 仿真 Philips Hue 设备的项目 ,需要这么几个库NeoPixelBusaJsonTimeNtpClient,同时还需要修改一些相关的配置。

因此官方推荐使用这个脚本安装,比较简单:

注意:如果是 Mac OS,需要将下面脚本中的 $HOME/Arduino/libraries/ 改为 $HOME/Documents/Arduino/libraries/

mkdir -p $HOME/Arduino/libraries/
cd $HOME/Arduino/libraries/
git clone --branch 2.1.4 https://github.com/Makuna/NeoPixelBus.git
git clone https://github.com/interactive-matter/aJson.git
git clone https://github.com/PaulStoffregen/Time.git
git clone https://github.com/gmag11/NtpClient.git
sed -i -e 's|#define PRINT_BUFFER_LEN 256|#define PRINT_BUFFER_LEN 4096|g'  aJson/aJSON.h
cd -
git clone https://github.com/probonopd/ESP8266HueEmulator.git
sed -i -e 's|#include "/secrets.h"|//#include "/secrets.h"|g' ESP8266HueEmulator/ESP8266HueEmulator/ESP8266HueEmulator.ino
sed -i -e 's|//const char|const char|g' ESP8266HueEmulator/ESP8266HueEmulator/ESP8266HueEmulator.ino

接着,我们只需要打开相应的 ino 文件,并编译烧录代码到设备上。

步骤2:连接设备

在完成上一步后,让我们打开 Arduino 的控制台,来看看相应的日志。

Starting SSDP...
SSDP Started

然后,我们需要在手机上安装相应的 Philips Hue 软件,过程如下所示:

Philips Hue 连接 ESP8266 模拟设备

如果不能在应用上查找到相应的设备,那么我们需要手动输入 IP 设备地址。随后,我们就可以连接上设备,对应的控制台就有相应的日志:

4090
{"name":"hue emulator","swversion":"81012917","bridgeid":"5CCF7FFFFEB147DA","portalservices":false,"linkbutton":true,"mac":"5C:CF:7F:B1:47:DA","dhcp":true,"ipaddress":"192.168.199.158","netmask":"255.255.255.0","gateway":"192.168.199.1","apiversion":"1.3.0","timezone":"Europe/London","whitelist":{"api":{"name":"clientname#devicename"}},"swupdate":{"text":"","notify":false,"updatestate":0,"url":""}}
4983
{"1":{"type":"Extended color light","name":"Hue LightStrips 1","uniqueid":"AA:BB:CC:DD:EE:FF:00:11-1","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}},"2":{"type":"Extended color light","name":"Hue LightStrips 2","uniqueid":"AA:BB:CC:DD:EE:FF:00:11-2","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}},"3":{"type":"Extended color light","name":"Hue LightStrips 3","uniqueid":"AA:BB:CC:DD:EE:FF:00:11-3","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}},"4":{"type":"Extended color light","name":"Hue LightStrips 4","uniqueid":"AA:BB:CC:DD:EE:FF:00:11-4","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}},"5":{"type":"Extended color light","name":"Hue LightStrips 5","uniqueid":"AA:BB:CC:DD:EE:FF:00:11-5","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}},"6":{"type":"Extended color light","name":"Hue LightStrips 6","uniqueid":"AA:BB:CC:DD:EE:FF:00:11-6","modelid":"LST001","state":{"on":false,"hue":0,"bri":0,"sat":0,"xy":[0.00000,0.00000],"ct":500,"alert":"none","effect":"none","colormode":"hs","reachable":true}}}
5171
{}

除此,我们还能看到一些相应的 Hue 设备的其他信息:

88565
{"1":{"name":"起居室","lights":["1","2"]}}
88613
{"name":"注入能量","owner":"api","picture":"","lastupdated":"","recycle":false,"locked":false,"version":2,"lights":["1","2"]}
88780
{"name":"静心阅读","owner":"api","picture":"","lastupdated":"","recycle":false,"locked":false,"version":2,"lights":["1","2"]}
89260
{"name":"渐暗","owner":"api","picture":"","lastupdated":"","recycle":false,"locked":false,"version":2,"lights":["1","2"]}
89343
{"name":"集中精神","owner":"api","picture":"","lastupdated":"","recycle":false,"locked":false,"version":2,"lights":["1","2"]}
89430
{"name":"放松休息","owner":"api","picture":"","lastupdated":"","recycle":false,"locked":false,"version":2,"lights":["1","2"]}
89551
{"name":"夜灯","owner":"api","picture":"","lastupdated":"","recycle":false,"locked":false,"version":2,"lights":["1","2"]}
89622
{"name":"热带黎明","owner":"api","picture":"","lastupdated":"","recycle":false,"locked":false,"version":2,"lights":["1","2"]}
{}
90369
{"name":"北极光","owner":"api","picture":"","lastupdated":"","recycle":false,"locked":false,"version":2,"lights":["1","2"]}

步骤3:总结与问题

尽管,我们能使用 ESP8266 模拟 Philips Hue 设备,但是我们并不能使用 Homekit 或者 Home Assistant 进行直接控制。这样一来,还是模拟 Wemo 好用。

尚未评分
您的评分将帮助我们做出更好的玩法

观光\评论区

Copyright © 2017 玩点什么. All Rights Reserved.