Skip to content

Commit

Permalink
esp_homekit_sdk: Add all the required code, dependencies, tools, docs…
Browse files Browse the repository at this point in the history
…, examples
  • Loading branch information
shahpiyushv committed Sep 25, 2020
1 parent fe486b5 commit 2e4cbcf
Show file tree
Hide file tree
Showing 237 changed files with 42,650 additions and 1 deletion.
41 changes: 41 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.config
*.o
*.pyc


# Example project files
examples/**/sdkconfig
examples/**/sdkconfig.old
examples/**/build

# emacs
.dir-locals.el

# eclipse setting
.settings

# vscode
.vscode

# Doc build artifacts
docs/*/_build/
docs/*/doxygen-warning-log.txt
docs/*/sphinx-warning-log.txt
docs/*/sphinx-warning-log-sanitized.txt
docs/*/xml/
docs/*/xml_in/
docs/*/man/
docs/doxygen_sqlite3.db

# MacOS directory files
.DS_Store

# Tools
tools/factory_nvs_gen/*.bin
tools/factory_nvs_gen/*.csv

# Patch files
*.patch

#CTags
tags
92 changes: 92 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
stages:
- build

build_homekit_examples:
stage: build
image: $CI_DOCKER_REGISTRY/esp32-ci-env
tags:
- build

variables:
IDF_PATH: "$CI_PROJECT_DIR/esp-idf"
GIT_STRATEGY: clone

artifacts:
paths:
- examples/fan/build/*.bin
- examples/fan/build/*.elf
- examples/fan/build/*.map
- examples/fan/build/bootloader/*.bin
expire_in: 6 mos

before_script:
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo -n $GITLAB_KEY >> ~/.ssh/id_rsa_base64
- base64 --decode --ignore-garbage ~/.ssh/id_rsa_base64 > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- echo -e "Host gitlab.espressif.cn\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config

script:
- git submodule update --init --recursive
# Cloning esp-idf
- git clone -b release/v4.2 --recursive --depth 1 https://github.com/espressif/esp-idf.git
- cd esp-idf
- ./install.sh
- . export.sh

- cd ../examples/fan
- idf.py build
- cd ../bridge
- idf.py build
- cd ../lightbulb
- idf.py build
- cd ../smart_outlet
- idf.py build
- cd ../data_tlv8
- idf.py build
- cd ../aws-iot
- mkdir components
- cd components
- git clone --depth 1 --single-branch --recursive https://github.com/espressif/esp-aws-iot.git
- export AWS_IOT_PATH=$PWD/esp-aws-iot
- cd ..
- touch main/certs/device.crt main/certs/device.key
- idf.py build
- cd ../emulator
- idf.py build
- cd ../ethernet_bridge
- idf.py build
- cd ../fan
- rm -rf build sdkconfig sdkconfig.old
- make defconfig
- make -j4
- cd ../bridge
- rm -rf build sdkconfig sdkconfig.old
- make defconfig
- make -j4
- cd ../lightbulb
- rm -rf build sdkconfig sdkconfig.old
- make defconfig
- make -j4
- cd ../smart_outlet
- rm -rf build sdkconfig sdkconfig.old
- make defconfig
- make -j4
- cd ../data_tlv8
- rm -rf build sdkconfig sdkconfig.old
- make defconfig
- make -j4
- cd ../aws-iot
- rm -rf build sdkconfig sdkconfig.old
- touch main/certs/device.crt main/certs/device.key
- make defconfig
- make -j4
- cd ../emulator
- rm -rf build sdkconfig sdkconfig.old
- make defconfig
- make -j4
- cd ../ethernet_bridge
- rm -rf build sdkconfig sdkconfig.old
- make defconfig
- make -j4
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "components/homekit/json_parser/upstream"]
path = components/homekit/json_parser/upstream
url = https://github.com/shahpiyushv/json_parser.git
[submodule "components/homekit/json_generator/upstream"]
path = components/homekit/json_generator/upstream
url = https://github.com/shahpiyushv/json_generator.git
3 changes: 3 additions & 0 deletions MFI_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ESP HomeKit SDK (MFi)

The Open source variant of esp-homekit-sdk cannot be used for commercial products. If you want to build commercial products and have an MFi License already, please get in touch with us by visiting [here](https://www.espressif.com/en/products/sdks/esp-homekit-sdk).
128 changes: 127 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,129 @@
# ESP HomeKit SDK
## Introduction

Espressif HomeKit SDK developed in-house
[HomeKit](https://developer.apple.com/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 SoCs.

> Note: If you want to use HomeKit for commercial products, please check [here](https://www.espressif.com/en/products/sdks/esp-homekit-sdk) 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.
> If you want to use a port of Apple's ADK instead, please check [here](https://github.com/espressif/esp-apple-homekit-adk)
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](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html).

### Get esp-homekit-sdk

Please clone this repository using the below command:

```text
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`

### Compile and Flash

You can use esp-homekit-sdk with any ESP32 or ESP32-S2 board. We have provided multiple examples for reference. Compile and flash as below (fan used as example):

```text
$ 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>
$ idf.py 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](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/provisioning/provisioning.html#provisioning-tools) 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.

### 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](#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](https://www.uuidgenerator.net/) 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.

```text
$ 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](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/storage/nvs_partition_gen.html#) 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.

```text
$ 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](MFI_README.md).

## Reporting issues

You can report issues directly on [Github issues](https://github.com/espressif/esp-homekit-sdk/issues).
9 changes: 9 additions & 0 deletions components/button/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set(COMPONENT_ADD_INCLUDEDIRS ./button/include)

# Edit following two lines to set component requirements (see docs)
set(COMPONENT_REQUIRES )
set(COMPONENT_PRIV_REQUIRES )

set(COMPONENT_SRCS ./button/button.c ./button/button_obj.cpp)

register_component()
6 changes: 6 additions & 0 deletions components/button/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
menu "Button"
config IO_GLITCH_FILTER_TIME_MS
int "IO glitch filter timer ms (10~100)"
range 10 100
default 50
endmenu
Loading

0 comments on commit 2e4cbcf

Please sign in to comment.