Skip to content

Commit

Permalink
The first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lisir233 committed Jul 29, 2023
0 parents commit 4d4c4c1
Show file tree
Hide file tree
Showing 733 changed files with 101,671 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
.vscode
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)

if(NOT DEFINED ENV{HOMEKIT_PATH})
message(FATAL_ERROR "Please set HOMEKIT_PATH to esp-homekit-sdk repo")
endif(NOT DEFINED ENV{HOMEKIT_PATH})

if(DEFINED ENV{RMAKER_PATH})
set(RMAKER_PATH $ENV{RMAKER_PATH})
else()
set(RMAKER_PATH ${CMAKE_CURRENT_LIST_DIR}/../..)
endif(DEFINED ENV{RMAKER_PATH})

# Add RainMaker components and other common application components
set(EXTRA_COMPONENT_DIRS $ENV{HOMEKIT_PATH}/components/homekit ${RMAKER_PATH}/components/esp-insights/components ${RMAKER_PATH}/components ${RMAKER_PATH}/examples/common components)

set(PROJECT_VER "1.0")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(esp_smart_light_controller
)
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#

ifeq ($(HOMEKIT_PATH),)
$(error Please set HOMEKIT_PATH to esp-homekit-sdk repo)
endif

PROJECT_NAME := homekit_switch
PROJECT_VER := 1.0

# Add RainMaker components and other common application components
EXTRA_COMPONENT_DIRS += $(PROJECT_PATH)/../../components $(PROJECT_PATH)/../common $(HOMEKIT_PATH)/components/homekit

include $(IDF_PATH)/make/project.mk
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# HomeKit Switch Example

This example demonstrates ESP RainMaker + HomeKit integration using the [esp-homekit-sdk](https://github.com/espressif/esp-homekit-sdk).

## Setup

Compiling this example would need the [esp-homekit-sdk](https://github.com/espressif/esp-homekit-sdk) repository. Clone it at a suitable location using:

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

Export the path to this repository using:

```
export HOMEKIT_PATH=/path/to/esp-homekit-sdk/
```

## Build and Flash firmware

Follow the ESP RainMaker Documentation [Get Started](https://rainmaker.espressif.com/docs/get-started.html) section to build and flash this firmware. Just note the path of this example. Note that, on bootup, the serial terminal will show 2 QR codes, one small and the other large. The smaller QR code is to be used for HomeKit pairing from the iOS Home app, whereas the larger one is supposed to be used with ESP RainMaker app.

> Note: HomeKit pairing can be done only after the device connects to the Wi-Fi network. However, if you have the MFi variant of the ESP HomeKit SDK, the QR code can be used for WAC Provisioning as well.
> The same QR code may be shown multiple times, so that it is available on screen whenever the device is in HomeKit pairing mode.
## What to expect in this example?

- This example uses the BOOT button and RGB LED on the ESP32-S2-Saola-1/ESP32-C3-DevKitC board to demonstrate a switch with HomeKit integration.
- The LED state (green color) indicates the state of the switch.
- Pressing the BOOT button will toggle the state of the switch and hence the LED. This will also reflect on the phone app.
- Toggling the button on the phone app should toggle the LED on your board, and also print messages like these on the ESP32-S2 monitor:

```
I (16073) app_main: Received value = true for Switch - power
```
- Once the board is set up, it can also be paired from iOS Home App. Follow the steps as given in next section.

## Using with iOS 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 RainMaker Device" 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 RainMaker Device added" message.
- Give a custom name, assign to a room, create scenes as required and you are done.

Now, any changes from ESP RainMaker will reflect on HomeKit and vice-versa. Changes from push button will reflect on both.

### LED not working?

The ESP32-S2-Saola-1 board has the RGB LED connected to GPIO 18. However, a few earlier boards may have it on GPIO 17. Please use `CONFIG_WS2812_LED_GPIO` to set the appropriate value.

### Reset to Factory

Press and hold the BOOT button for more than 3 seconds to reset the board to factory defaults. You will have to provision the board again to use it.
3 changes: 3 additions & 0 deletions components/app_wifi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
idf_component_register(SRCS "app_wifi_with_homekit.c"
INCLUDE_DIRS "."
PRIV_REQUIRES wifi_provisioning qrcode esp_hap_core esp_hap_platform nvs_flash)
68 changes: 68 additions & 0 deletions components/app_wifi/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
menu "App Wi-Fi Provisioning"

config APP_WIFI_PROV_SHOW_QR
bool "Show provisioning QR code"
default y
help
Show the QR code for provisioning.

choice APP_WIFI_PROV_TRANSPORT
bool "Provisioning Transport method"
default APP_WIFI_PROV_TRANSPORT_BLE
help
Wi-Fi provisioning component offers both, SoftAP and BLE transports. Choose any one.

config APP_WIFI_PROV_TRANSPORT_SOFTAP
bool "Soft AP"
config APP_WIFI_PROV_TRANSPORT_BLE
bool "BLE"
select BT_ENABLED
depends on IDF_TARGET_ESP32 || IDF_TARGET_ESP32C3
endchoice

config APP_WIFI_PROV_TRANSPORT
int
default 1 if APP_WIFI_PROV_TRANSPORT_SOFTAP
default 2 if APP_WIFI_PROV_TRANSPORT_BLE

config APP_WIFI_USE_WAC_PROVISIONING
bool "Apple WAC Provisioning"
depends on HAP_MFI_ENABLE
default n
help
"Use Apple WAC Provisioning"

config APP_WIFI_RESET_PROV_ON_FAILURE
bool
default y
prompt "Reset provisioned credentials and state machine after session failure"
help
Enable reseting provisioned credentials and state machine after session failure.
This will restart the provisioning service after retries are exhausted.

config APP_WIFI_PROV_MAX_RETRY_CNT
int
default 5
prompt "Max retries before reseting provisioning state machine"
depends on APP_WIFI_RESET_PROV_ON_FAILURE
help
Set the Maximum retry to avoid reconnecting to an inexistent AP or if credentials
are misconfigured. Provisioned credentials are erased and internal state machine
is reset after this threshold is reached.

config APP_WIFI_PROV_TIMEOUT_PERIOD
int "Provisioning Timeout"
default 10
help
Timeout (in minutes) after which the provisioning will auto stop. A reboot will be required
to restart provisioning. Set to 0 if you do not want provisioning to auto stop.
It is recommended to set this to 15 or 10 depending on the HomeKit spec version supported,
to match the WAC timeout.

config APP_WIFI_PROV_NAME_PREFIX
string "Provisioning Name Prefix"
default "PROV"
help
Provisioning Name Prefix.

endmenu
Loading

0 comments on commit 4d4c4c1

Please sign in to comment.