• Stars
    star
    518
  • Rank 82,385 (Top 2 %)
  • Language
    C
  • Created over 3 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ESP HomeKit SDK

Introduction

HomeKit is a framework developed by Apple for communicating with and controlling connected accessories in a user’s home using iOS devices. ESP HomeKit SDK has been developed in-house by Espressif to build Apple HomeKit compatible accessories using ESP32/ESP32-S2/ESP32-C3/ESP8266 SoCs.

Note: If you want to use HomeKit for commercial products, please check here for access to the MFi variant of this SDK. It has the exact same APIs as this and so, moving to it should be easy. However, commercial HomeKit products can be built only with ESP32/ESP32-S2/ESP32-C3 since ESP8266 cannot meet all the HomeKit Certification requirements.

If you want to use a port of Apple's ADK instead, please check here

Features of this SDK:

  • Easy APIs to implement all standard HomeKit profiles defined by Apple.
  • Facility to add customised accessory specific Services and Characteristics.
  • Samples (Fan, Lightbulb, Outlet, Bridge, Data-TLV8, Ethernet) to enable quick accessory development.
  • Support for ESP Unified Provisioning.

Get Started

Set up Host environment

Set up the host environment and ESP IDF (master branch) as per the steps given here.

If you are using ESP8266, set-up ESP8266-RTOS-SDK (master branch) as per the steps given here.

Get esp-homekit-sdk

Please clone this repository using the below command:

git clone --recursive https://github.com/espressif/esp-homekit-sdk.git

Note the --recursive option. This is required to pull in the JSON dependencies into esp-homekit-sdk. In case you have already cloned the repository without this option, execute this to pull in the submodules: git submodule update --init --recursive

If you had already cloned the repository and submodules earlier, you may have to execute git submodule sync --recursive once since the submodule paths have changed.

Compile and Flash

You can use esp-homekit-sdk with any ESP32, ESP32-S2, ESP32-C3 or ESP8266 board (though we have tested only with the ESP32-DevKit-C, ESP32-S2-Saola-1, ESP32-C3-DevKit-M-1, ESP8266-DevKit-C). We have provided multiple examples for reference. Compile and flash as below (fan used as example):

For ESP32/ESP32-S2/ESP32-C3

$ cd /path/to/esp-homekit-sdk/examples/fan
$ export ESPPORT=/dev/tty.SLAB_USBtoUART #Set your board's serial port here
$ idf.py set-target <esp32/esp32s2/esp32c3>
$ idf.py flash monitor

For ESP8266

$ cd /path/to/esp-homekit-sdk/examples/fan
$ export ESPPORT=/dev/tty.SLAB_USBtoUART #Set your board's serial port here
$ make defconfig
$ make flash monitor

As the device boots up, you will see two QR codes, a small one for HomeKit and a larger one for Wi-Fi provisioning. Please use any of the Espressif Provisioning Apps for Wi-Fi provisioning.

Note: For the Open source HomeKit SDK, the HomeKit QR code cannot be used for provisioning from the Home app. It can be used only for pairing, after the Wi-Fi provisioning is done. For provisioning from Home app, you will need the MFi variant of the SDK.

Note: If you want to use hard-coded credentials instead of Provisioning, please set the ssid and passphrase by navigating to idf.py menuconfig -> App Wi-Fi -> Source of Wi-Fi Credentials -> Use Hardcoded

After the device connects to your Home Wi-Fi network it can be added in the Home app

Add acccessory in the Home app

Open the Home app on your iPhone/iPad and follow these steps

  • Tap on "Add Accessory" and scan the small QR code mentioned above.
  • If QR code is not visible correctly, you may use the link printed on the serial terminal or follow these steps:
    • Choose the "I Don't Have a Code or Cannot Scan" option.
    • Tap on "Esp-Fan-xxxxxx" in the list of Nearby Accessories.
    • Select the "Add Anyway" option for the "Uncertified Accessory" prompt.
    • Enter 11122333 as the Setup code.
  • You should eventually see the "Esp-Fan-xxxxxx added" message.
  • Give a custom name, assign to a room, create scenes as required and you are done.

For ESP8266, the pairing may take a bit longer.

Changing the Setup Code

The HomeKit setup code can be changed by using the CONFIG_EXAMPLE_SETUP_CODE config option (idf.py menuconfig -> Example Configuration -> HomeKit Setup Code). Please also refer the HomeKit Setup Configuration below.

Using Standard Apple HomeKit Profiles

The examples provided in the SDK are for fan, outlet, lightbulb. For using any other standard profiles, please refer the files under components/homekit/hap_apple_profiles/.

Adding Custom Profiles

Please refer the Firmware Upgrades Custom Profile (components/homekit/extras/) to see how to add your own profile. You can use some UUID generator like this to generate your own UUIDs for the services and characteristics.

HomeKit Setup Configuration

As per the HomeKit requirements, the raw setup code should not be stored on the accessory. Instead, the SRP Salt and Verifier generated from the code should be stored. This salt-verifier combination, called as setup info in the ESP HomeKit SDK, needs to be unique for every accessory. This can be provided to the HAP Core using the hap_set_setup_info() API. Another parameter required for setup is the setup id, which also needs to be unique. It is provided to the HAP Core using hap_set_setup_id() API.

In order to ease the task of providing unique setup info and setup id for each accessory, instead of using the above APIs, the same information can be stored in a separate flash partition called factory_nvs (Please see the partitions_hap.csv file in any example). This allows to keep the same firmware image and just flash different factory_nvs images for different accessories. The factory_nvs image fan_factory.bin has been provided for Fan, which can be flashed using esptool. Custom images can be created using the factory_nvs_gen utility in tools/ as below

Usage:

./factory_nvs_gen.py 11122333 ES32 factory

Replace ES32 and 11122333 with the setup code and setup id of your choice. This has been tested with Python 3.7.3.

Flash this using the esptool as below.

$ esptool.py -p $ESPPORT write_flash 0x340000 factory.bin

To use the setup info from this image, you will have to disable the hardcoded setup code by setting CONFIG_EXAMPLE_SETUP_CODE=n (idf.py menuconfig -> Example Configuration -> Use hard-coded setup code -> disable).

The factory_nvs partition can also hold other information like serial numbers, cloud credentials, firmware verification keys, etc. For that, just create a CSV file as per the requirements of NVS Partition Generator Utility and provide it to the factory_nvs_gen using the --infile option. These variables (if stored as binary data) can then be read in the accessory code using hap_factory_keystore_get() API.

Sample CSV (say sample.csv)

key,type,encoding,value
app,namespace,,
serial_num,data,binary,12345

Usage:

./factory_nvs_gen.py --infile sample.csv 11122333 ES32 factory

Flash this using the same command given above.

$ esptool.py -p $ESPPORT write_flash 0x340000 factory.bin

Additional MFi requirements

If you have access to the MFi variant of esp-homekit-sdk, please check additional information here.

Reporting issues

You can report issues directly on Github issues.

More Repositories

1

esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
C
12,517
star
2

arduino-esp32

Arduino core for the ESP32
C++
12,308
star
3

esptool

Espressif SoC serial bootloader utility
Python
5,311
star
4

ESP8266_RTOS_SDK

Latest ESP8266 SDK based on FreeRTOS, esp-idf style.
C
3,232
star
5

esp-iot-solution

Espressif IoT Library. IoT Device Drivers, Documentations And Solutions.
C
1,751
star
6

esp-who

Face detection and recognition framework
C
1,594
star
7

esp-adf

Espressif Audio Development Framework
C
1,395
star
8

esp32-camera

C
1,259
star
9

vscode-esp-idf-extension

Visual Studio Code extension for ESP-IDF projects
TypeScript
944
star
10

ESP8266_NONOS_SDK

ESP8266 nonOS SDK
C
911
star
11

esp-at

AT application for ESP32/ESP32-C2/ESP32-C3/ESP32-C6/ESP8266
C
769
star
12

esp-mdf

Espressif Mesh Development Framework, limited maintain, recommend to use https://github.com/espressif/esp-mesh-lite
C
757
star
13

ESP8266_MP3_DECODER

A demo that should be run with ESP8266 Non-OS SDK
C
739
star
14

esp-drone

Mini Drone/Quadcopter Firmware for ESP32 and ESP32-S Series SoCs.
C
658
star
15

esp-box

The ESP-BOX is a new generation AIoT development platform released by Espressif Systems.
HTML
612
star
16

esp-apple-homekit-adk

This is a port for Apple's Open Source HomeKit ADK
C
598
star
17

esp-csi

Applications based on Wi-Fi CSI (Channel state information), such as indoor positioning, human detection
C
592
star
18

kicad-libraries

KiCad libraries for Espressif chips and modules
Python
580
star
19

esp-mqtt

ESP32 mqtt component
C
577
star
20

esp-matter

Espressif's SDK for Matter
C++
546
star
21

esp-hosted

Hosted Solution (Linux/MCU) with ESP32 (Wi-Fi + BT + BLE)
C
539
star
22

esp-skainet

Espressif intelligent voice assistant
C
500
star
23

ESP8266_AT

This project is not maintained, please use https://github.com/espressif/esp-at.
C
472
star
24

esp32-nesemu

Proof-of-concept NES emulator for the ESP32
C
471
star
25

esp-sr

Speech recognition
C
462
star
26

rust-esp32-example

Example of Rust integration into an ESP-IDF project, for ESP32 series of chips
Rust
421
star
27

esp-rainmaker

ESP RainMaker Agent for firmware development
C
415
star
28

esp-now

A connectionless Wi-Fi communication protocol
C
402
star
29

esp-dsp

DSP library for ESP-IDF
C
401
star
30

esp-dl

Espressif deep-learning library for AIoT applications
C++
369
star
31

openocd-esp32

OpenOCD branch with ESP32 JTAG support
C
334
star
32

esp-aliyun

Aliyun Iotkit-embedded, support esp32 & esp8266.
C
333
star
33

esp-idf-template

Template application for https://github.com/espressif/esp-idf
Makefile
323
star
34

esp-serial-flasher

Library for flashing Espressif SoCs from other MCUs.
C++
321
star
35

idf-eclipse-plugin

Espressif-IDE (based on Eclipse CDT) for ESP-IDF CMake based projects 4.x and above
Java
289
star
36

esp-dev-kits

Docs, Schematics, Factory Firmwares for ESP Development Kits
C
287
star
37

esp-va-sdk

Espressif's Voice Assistant SDK: Alexa, Google Voice Assistant, Google DialogFlow
C
273
star
38

esp-tflite-micro

TensorFlow Lite Micro for Espressif Chipsets
C++
271
star
39

esp-usb-bridge

USB to UART&JTAG bridge, implemented on ESP32-S2 or ESP32-S3
C
271
star
40

esp-aws-iot

AWS IoT SDK for ESP32 based chipsets
C
247
star
41

esptool-js

Javascript implementation of flasher tool for Espressif chips, running in web browser using WebSerial.
TypeScript
241
star
42

ESP31_RTOS_SDK

ESP31B SDK based on FreeRTOS. For ESP32 please see http://github.com/espressif/esp-idf
HTML
189
star
43

esp-idf-provisioning-android

Android Provisioning application for ESP-IDF Unified provisioning
Java
184
star
44

esp-azure

SDK to connect ESP8266 and ESP32 to Microsoft Azure IoT services
C
174
star
45

esp-jumpstart

Jumpstart from concept to production
C
167
star
46

esp-gdbstub

C
157
star
47

esp-protocols

Collection of ESP-IDF components related to networking protocols
C
156
star
48

esp32-wifi-lib

ESP32 WiFi stack precompiled libraries
Shell
153
star
49

esp32-doom

A proof-of-concept port of PrBoom to the ESP32. Needs psram hardware.
C++
151
star
50

esp-google-iot

Google Cloud IoT SDK as an ESP-IDF Component
C
144
star
51

esp-bsp

Board support components for Espressif development boards
C
141
star
52

esp8266-rtos-sample-code

C
131
star
53

esp-iot-bridge

A smart bridge to make both ESP and the other MCU or smart device can access the Internet.
C
129
star
54

esp-idf-provisioning-ios

Swift
125
star
55

idf-extra-components

Additional components for ESP-IDF, maintained by Espressif
C
122
star
56

esp32-arduino-lib-builder

C
120
star
57

esp-nn

Optimised Neural Network functions for Espressif chipsets
Assembly
103
star
58

esp-zigbee-sdk

Espressif Zigbee SDK
C
99
star
59

idf-installer

ESP IDF Windows Installer
Inno Setup
92
star
60

esp-insights

ESP Insights: A remote diagnostics/observability framework for connected devices
C
91
star
61

esp-rainmaker-android

ESP RainMaker Android app sources
Java
85
star
62

esp-thread-br

Espressif Thread Border Router SDK
C
82
star
63

esp-mesh-lite

A lite version Wi-Fi Mesh, each node can access the network over the IP layer.
C
79
star
64

book-esp32c3-iot-projects

《ESP32-C3 物联网工程开发实战》配套代码
Swift
77
star
65

esp-lwip

Fork of lwIP (https://savannah.nongnu.org/projects/lwip/) with ESP-IDF specific patches
C
77
star
66

esp-ali-smartliving

阿里云生活物联网平台 & 天猫精灵 IoT 开放平台
C
75
star
67

usb-pids

Customer-allocated USB PIDs under the Espressif VID
Shell
75
star
68

pytest-embedded

A pytest plugin that designed for embedded testing
Python
74
star
69

esp32-bt-lib

ESP32 Bluetooth stack (below HCI layer) precompiled libraries
67
star
70

esp-modbus

ESP-Modbus - the officially suppported library for Modbus protocol (serial RS485 + TCP over WiFi or Ethernet).
C
67
star
71

esp8266-nonos-sample-code

C
65
star
72

esp-qcloud

基于 ESP-IDF 原生开发接入腾讯 IoT Explorer,支持 ESP32/ESP32S2,快速实现腾讯连连控制。
C
65
star
73

esp32c3-direct-boot-example

Example of ESP32-C3 (rev. 3 and later) "direct boot" feature.
CMake
64
star
74

esp-idf-cxx

C++ wrapper classes for ESP-IDF components.
C++
63
star
75

esp-wasmachine

The Machine which can run WASM applications.
C
50
star
76

freertos-gdb

Python module for operating with freeRTOS kernel objects in GDB
Python
48
star
77

svd

SVD files for Espressif devices
47
star
78

binutils-esp32ulp

Binutils fork with support for the ESP32 ULP co-processor
C
46
star
79

esp-moonlight

C
44
star
80

xtensa-isa-doc

TeX
42
star
81

esp-privilege-separation

Espressif Privilege Separation Framework
C
41
star
82

esp-rainmaker-ios

ESP RainMaker iOS app sources
Swift
41
star
83

openocd-on-esp32

OpenOCD port running on ESP32-S3 microcontrollers
C
40
star
84

esp-adf-libs

C
38
star
85

idf-component-manager

Tool for installing ESP-IDF components
Python
37
star
86

ESP8266_RTOS_ALINK_DEMO

Alink 1.0 早期版本
Assembly
36
star
87

esp-wolfssl

WolfSSL port for ESP-IDF & ESP8266_RTOS_SDK
C
35
star
88

esp-joylink

Demo project for JD joylink, support esp32 & esp8266.
C
34
star
89

esp31-smsemu

C
34
star
90

esp8266-alink-v1.0

alink v1.0
C
32
star
91

esp-faq

Python
31
star
92

esp-launchpad

Configurable Browser-based Image Flasher
CSS
31
star
93

esp32-alink-demo

Demo project for alink, include embed and SDS
C
30
star
94

esp32-iotivity

Guide you to make your ESP32 support OCF/OIC.
C
29
star
95

newlib-esp32

Version of newlib used in ESP32 ROM and ESP-IDF
C
29
star
96

esp8266-alink-sds

Demo project for alink SDS
C
27
star
97

esp-wdf

Espressif WASM Development Framework.
C
27
star
98

idf-env

idf-env tool helps set up and manage ESP-IDF installations
Rust
25
star
99

esp-cryptoauthlib

Release only fork of https://github.com/MicrochipTech/cryptoauthlib
C
23
star
100

esp-wireless-drivers-3rdparty

Wi-Fi and BT drivers packaged for integration into 3rd party repositories. Work in progress.
C
22
star