My Firmware

My Firmware

Embedded development

© 2020

Apple HomeKit devices using ESP8266

In the past I built my custom home automation system and while it certainly was a good project for a high-schooler it lacked important features such as easy device management and also contributed to the sad state of IoT - too many isolated systems, no standardized connection between them.

In custom IoT devices HomeKit integration can be achieved two ways - using HomeBridge a Node.js project aiming at creating a universal interface to all IoT devices and bringing them to HomeKit and a custom implementation of the Home Access Protocol (HAP) on a WiFi or Bluetooth enabled device.

Fortunately the specification for the HAP was released for non-commercial use by Apple at WWDC 2017, which meant that the reverse engineered implementation could be replaced by a correct one.

I recently built a 3D printer enclosure which utilizes a small piece of a LED strip and since I had almost 2.5 meters of it left I decided to build a light under my bed that would be controlled via HomeKit. During the process I also added a DHT-11 thermometer/humidity sensor.

Hardware

The schematic of the device is pretty simple, there is the ESP8266, an N-channel MOSFET, DC-DC buck converter and the DHT-11. There are also some other small parts such as filtering caps and LEDs.

The device is powered using a 2.1 mm barrel jack, the input voltage should be around 12 V. There is also a header for programming. The programming is done using a serial adapter with DTR and RTS, however the voltage levels should be 3.3 V.

Software

As for the software there is a great HAP implementation by Maxim Kulkin https://github.com/maximkulkin/esp-homekit-demo. The code uses esp-open-rtos therefore the whole program is coded in C. For this project I followed guide mentioned here: Build instructions ESP8266 (Docker) · maximkulkin/esp-homekit-demo Wiki · GitHub and then modified the example esp-homekit-demo/led.c at master · maximkulkin/esp-homekit-demo · GitHub . There was also need to include code for PWM and DHT which can be found in the RTOS extras here: esp-open-rtos/extras at master · SuperHouse/esp-open-rtos · GitHub.

Conclusion

Overall I must say that developing the device using this approach using the RTOS library has been much more pleasant than using HomeBridge. The device has been really stable, doesn’t need another device and is ready to use very fast after startup.

The only thing I am missing now is a better automation in the HomeKit ecosystem however that is up to Apple to fix.