最近在探索基于 ESP8266 构建的智能家居系统,之前尝试过使用 ESP8266 连接到 Amazon Echo,便开始寻找适合 ESP8266 的 Homekit 方案。寻觅中,便找到了 ESP8266-HomeKit,它在 ESP8266 上采用 API 方法来运行 HomeKit 服务。该项目使用 ESP8266_RTOS_SDK 和 WolfCrypt 3.9.8 作为加密。但是,它不会提供认证的HomeKit设备。
本文翻译自官方的构建指南:Build instructions for ESP8266-HomeKit
为了搭建 ESP8266-HomeKit,我们需要准备下面的这些工具:
xtensa-lx106-elf-gcc
工具链。推荐的安装方式是在你的计算机上安装[esp-open-sdk](https://github.com/pfalcon/esp-open-sdk)
。使用 make toolchain esptool libhal STANDALONE=n
安装ESP8266/RTOS SDK
1.如果你是使用 git
克隆 ESP8266_RTOS_SDK,首先编辑:ESP8266_RTOS_SDK/.git/info/exclude
,在其中添加 /ESP8266-HomeKit*/
。
esp-open-sdk$ git clone https://github.com/espressif/ESP8266_RTOS_SDK.git
esp-open-sdk$ sudo nano ESP8266_RTOS_SDK/.git/info/exclude
如下图所示:
2.然后在 ESP8266_RTOS_SDK
目录中,使用 git 克隆 ESP8266-HomeKit 及 ESP8266-HomeKit-Demo
esp-open-sdk$ cd ESP8266_RTOS_SDK
ESP8266_RTOS_SDK$ git clone https://github.com/HomeACcessoryKid/ESP8266-HomeKit.git
ESP8266_RTOS_SDK$ git clone https://github.com/HomeACcessoryKid/ESP8266-HomeKit-Demo.github.com
3.这时,您的文件夹结构应如下所示:
ESP8266_RTOS_SDK
├── ESP8266-HomeKit
├── ESP8266-HomeKit-Demo
├── LICENSE
├── Makefile
├── README.md
├── bin
├── documents
├── driver_lib
├── examples
├── extra_include
├── include
├── ld
├── lib
├── third_party
└── tools
跳转到 ESP8266-HomeKit 目录,然后执行 deploy.sh
脚本。
ESP8266_RTOS_SDK$ cd ESP8266-HomeKit
ESP8266-HomeKit$ ./deploy.sh
它将创建下面的文件:
如果一切顺利,你应该会看到:
...
xtensa-lx106-elf-ar: creating .output/eagle/debug/lib/libhkc.a
rm -f -r _libhkc
########## success ###########
deployed lib/libhkc.a and include/hkc.h
ESP8266-HomeKit$
现在再按照 ESP8266-HomeKit-Demo wiki 的说明进行下一步。
为了方便,需要在 wolfSSL 3.9.8 一个小节里,包含 src(路径:hkc/include/wolfssl)和 hkc(路径:hkc/wolfcrypt)文件。
.
└── wolfcrypt
├── COPYING
├── LICENSING
├── Makefile
├── include
│ └── wolfssl
│ ├── ssl.h
│ ├── version.h
│ └── wolfcrypt
│ ├── arc4.h
│ ├── asn.h
│ ├── asn_public.h
│ ├── chacha.h
│ ├── chacha20_poly1305.h
│ ├── curve25519.h
│ ├── ed25519.h
│ ├── error-crypt.h
│ ├── fe_operations.h
│ ├── ge_operations.h
│ ├── hash.h
│ ├── hmac.h
│ ├── integer.h
│ ├── logging.h
│ ├── memory.h
│ ├── misc.h
│ ├── mpi_class.h
│ ├── mpi_superclass.h
│ ├── poly1305.h
│ ├── random.h
│ ├── rsa.h
│ ├── settings.h
│ ├── settings.h.0
│ ├── sha.h
│ ├── sha256.h
│ ├── sha512.h
│ ├── srp.h
│ ├── types.h
│ ├── visibility.h
│ └── wc_port.h
└── src
├── Makefile
├── chacha.c
├── chacha20_poly1305.c
├── curve25519.c
├── ed25519.c
├── fe_operations.c
├── ge_operations.c
├── ge_operations.c.0
├── hash.c
├── hmac.c
├── integer.c
├── misc.c
├── misc.c.0
├── poly1305.c
├── random.c
├── sha256.c
├── sha512.c
└── srp.c
我们必须更改 3 个文件,这些文件将记录在文件树下面。请下载您自己的副本并验证文件的相等性(* .0是原件)
$ diff ESP8266-HomeKit/wolfcrypt/src/ge_operations.c.0 ESP8266-HomeKit/wolfcrypt/src/ge_operations.c
770c770
< static ge_precomp base[32][8] = {
---
> static ge_precomp ICACHE_RODATA_ATTR base[32][8] = {
2225c2225
< static ge_precomp Bi[8] = {
---
> static ge_precomp ICACHE_RODATA_ATTR Bi[8] = {
$ diff ESP8266-HomeKit/wolfcrypt/src/misc.c.0 ESP8266-HomeKit/wolfcrypt/src/misc.c
48,50c48,50
< #if !defined(WOLFSSL_MISC_INCLUDED) && !defined(NO_INLINE)
< #error misc.c does not need to be compiled when not defined NO_INLINE
< #endif
---
> // #if !defined(WOLFSSL_MISC_INCLUDED) && !defined(NO_INLINE)
> // #error misc.c does not need to be compiled when not defined NO_INLINE
> // #endif
$ diff include/wolfssl/wolfcrypt/settings.h.0 include/wolfssl/wolfcrypt/settings.h
33a34,35
> #define WOLFSSL_USER_SETTINGS
>
请注意
:应删除其他src文件,以防止使用过多的 irom 大小。
观光\评论区