Mixiaoxiao / Arduino-HomeKit-ESP8266

Native Apple HomeKit accessory implementation for the ESP8266 Arduino core.
MIT License
1.48k stars 278 forks source link
arduino arduino-library esp32 esp32-arduino esp8266 esp8266-arduino homekit

Arduino HomeKit ESP8266

中文说明 | Português Brasileiro | Русский

Apple HomeKit accessory server library for ESP8266 Arduino

This Arduino library is a native Apple HomeKit accessory implementation for the ESP8266 Arduino core, and works without any additional bridges.

This project is mainly based on esp-homekit for ESP-OPEN-RTOS.

I ported the RTOS-based implementation of esp-homekit to the pure Arduino environment, aimed at easy and fast building project using Arduino IDE (or Eclipse with sloeber, PlatformIO).

Enjoy the "one-key" build, "one-key" upload, and work to link various other Arduino libraries with Apple HomeKit!

Here is a discussion about the RTOS is required for running Apple HomeKit, and this project is a proof of concept that Apple HomeKit can be implemented and work fine without the RTOS.

This library is built with ESP8266 Arduino Core 2.6.3. Lower versions may compile with errors.

For ESP32, see Arduino-HomeKit-ESP32. The HomeKit running on ESP32 has a GREAT PERFORMANCE which is 10x faster than ESP8266.

Preview

Preview

Setup code of the example sketch

111-11-111

Usage

  1. Define your accessory in a .c file to enjoy the convenient "Macro" style declaration. You can also define your accessory in a .ino file using C++ code.
        homekit_accessory_t *accessories[] = ...
        homekit_server_config_t config = {
            .accessories = accessories,
            .password = "111-11-111",
            //.on_event = on_homekit_event, //optional
            //.setupId = "ABCD" //optional
        };
  2. In your sketch

        #include <arduino_homekit_server.h>;
    
        //access the config defined in C code
        extern "C" homekit_server_config_t config; 
    
        void setup() {
            WiFi.begin(ssid, password);
            arduino_homekit_setup(&config);
        }
    
        void loop() {
            arduino_homekit_loop();
        }

    Done.

Performance

Notice: You should set the ESP8266 CPU to run at 160MHz (at least during the pairing process), to avoid the tcp-socket disconnection from iOS device caused by timeout.

All pairing process takes ~14s after you input the setup-code on your iPhone. Notice that Preinit require ~9s before you can start to pair.

Heap (memory)

The heap is critical for ESP8266 with full TCP/IP support. ESP8266 easily crashes when the memory is lower than ~5000.

I tried to make WolfSSL crypto work safely on ESP8266 with better performance and lower memory or a trade-off. See details in next section.

Here are the free heap values of running the example sketch:

After memory optimization in v1.1.0:

WolfSSL

Storage

WatchDog

Recommended settings in IDE

Arduino port

Troubleshooting

Change Log

v1.4.0

v1.3.0

v1.2.0

v1.1.0

v1.0.1

Thanks