esp-homekit 在 ESP8266 的移植
中文版本
esp-homekit 是 Apple HomeKit
配件服务器库,可以在 esp8266
和 esp32
上使用,以下是 esp-homekit 是基于 ESP8266_RTOS_SDK 在 esp8266
上的移植步骤。
-
下载这些库到
compnents
,并重命名文件夹1. git clone --recursive https://github.com/maximkulkin/esp-homekit homekit 2. git clone --recursive https://github.com/maximkulkin/esp-http-parser http-parser 3. git clone --recursive https://github.com/maximkulkin/esp-wolfssl wolfssl
-
修改
makefile
文件PROJECT_NAME = esp8266-homekit-led CFLAGS += -DHOMEKIT_SHORT_APPLE_UUIDS include $(IDF_PATH)/make/project.mk
-
修改
main
文件下的component.mk
COMPONENT_DEPENDS := homekit
-
把项目的
wifi.h.sample
移到main
文件夹下,然后修改为wifi.h
,最后写入自己的WiFi
的SSID
和 密码#define WIFI_SSID "mywifi" #define WIFI_PASSWORD "mypassword"
-
修改
led demo
,详细见目录下的led.c
... #include <homekit/homekit.h> #include <homekit/characteristics.h> ... homekit_accessory_t *accessories[] = { HOMEKIT_ACCESSORY(.id=1, .category=homekit_accessory_category_lightbulb, .services=(homekit_service_t*[]){ HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics=(homekit_characteristic_t*[]){ HOMEKIT_CHARACTERISTIC(NAME, "Sample LED"), HOMEKIT_CHARACTERISTIC(MANUFACTURER, "PYHOME"), HOMEKIT_CHARACTERISTIC(SERIAL_NUMBER, "025A2BABF19D"), HOMEKIT_CHARACTERISTIC(MODEL, "MyLED"), HOMEKIT_CHARACTERISTIC(FIRMWARE_REVISION, "0.1"), HOMEKIT_CHARACTERISTIC(IDENTIFY, led_identify), NULL }), HOMEKIT_SERVICE(LIGHTBULB, .primary=true, .characteristics=(homekit_characteristic_t*[]){ HOMEKIT_CHARACTERISTIC(NAME, "Sample LED"), HOMEKIT_CHARACTERISTIC( ON, false, .getter=led_on_get, .setter=led_on_set ), NULL }), NULL }), NULL }; homekit_server_config_t config = { .accessories = accessories, .password = "111-11-111", .setupId="1SP0", }; void on_wifi_ready() { homekit_server_init(&config); } ...
-
注意,需要在
menuconfig
中使能MDNS
和IPV6
# mDNs CONFIG_ENABLE_MDNS=y # IPV6 CONFIG_LWIP_IPV6=y
该项目参考 esp32-homekit-led 中的 makefile
和 项目目录
Although already forbidden by the sources and subsequent licensing, it is not allowed to use or distribute this software for a commercial purpose.
HomeKit Accessory Protocol (HAP) is Apple’s proprietary protocol that enables third-party accessories in the home (e.g., lights, thermostats and door locks) and Apple products to communicate with each other. HAP supports two transports, IP and Bluetooth LE. The information provided in the HomeKit Accessory Protocol Specification (Non-Commercial Version) describes how to implement HAP in an accessory that you create for non-commercial use and that will not be distributed or sold.
The HomeKit Accessory Protocol Specification (Non-Commercial Version) can be downloaded from the HomeKit Apple Developer page.
esp-homekit is Apple HomeKit
accessory server library, which can be used on esp8266 and esp32, the following is esp-homekit based on ESP8266_RTOS_SDK migration steps on esp8266.
-
download these libraries to components and rename folder
1. git clone --recursive https://github.com/maximkulkin/esp-homekit homekit 2. git clone --recursive https://github.com/maximkulkin/esp-http-parser http-parser 3. git clone --recursive https://github.com/maximkulkin/esp-wolfssl wolfssl
-
modify the makefile
PROJECT_NAME = esp8266-homekit-led CFLAGS += -DHOMEKIT_SHORT_APPLE_UUIDS include $(IDF_PATH)/make/project.mk
-
modify the
component.mk
under mainCOMPONENT_DEPENDS := homekit
-
move the project's
wifi.h.sample
to main folder, then modify it towifi.h
, finally write your WiFi SSID and password#define WIFI_SSID "mywifi" #define WIFI_PASSWORD "mypassword"
-
modify led demo, see the
led.c
for details... #include <homekit/homekit.h> #include <homekit/characteristics.h> ... homekit_accessory_t *accessories[] = { HOMEKIT_ACCESSORY(.id=1, .category=homekit_accessory_category_lightbulb, .services=(homekit_service_t*[]){ HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics=(homekit_characteristic_t*[]){ HOMEKIT_CHARACTERISTIC(NAME, "Sample LED"), HOMEKIT_CHARACTERISTIC(MANUFACTURER, "PYHOME"), HOMEKIT_CHARACTERISTIC(SERIAL_NUMBER, "025A2BABF19D"), HOMEKIT_CHARACTERISTIC(MODEL, "MyLED"), HOMEKIT_CHARACTERISTIC(FIRMWARE_REVISION, "0.1"), HOMEKIT_CHARACTERISTIC(IDENTIFY, led_identify), NULL }), HOMEKIT_SERVICE(LIGHTBULB, .primary=true, .characteristics=(homekit_characteristic_t*[]){ HOMEKIT_CHARACTERISTIC(NAME, "Sample LED"), HOMEKIT_CHARACTERISTIC( ON, false, .getter=led_on_get, .setter=led_on_set ), NULL }), NULL }), NULL }; homekit_server_config_t config = { .accessories = accessories, .password = "111-11-111", .setupId="1SP0", }; void on_wifi_ready() { homekit_server_init(&config); } ...
-
note! you need to enable MDNS and IPV6 in menuconfig
# mDNs CONFIG_ENABLE_MDNS=y # IPV6 CONFIG_LWIP_IPV6=y
This project refers to the makefile and project directory from esp32-homekit-led
Although already forbidden by the sources and subsequent licensing, it is not allowed to use or distribute this software for a commercial purpose.