Generating a QR Code for ESP32 HomeKit Demo

If you’re looking to integrate your ESP32 with Apple’s HomeKit, you’re in luck. With a bit of setup, you can generate a QR code to streamline the pairing process. Let’s dive into the steps required to generate a QR code for your HomeKit accessory using the esp32-homekit-demo repository.

Cloning the Repository

First, clone the esp32-homekit-demo repository:

git clone --recursive https://github.com/AchimPieters/esp32-homekit-demo.git

This will download the demo project along with its submodules.

Accessory Setup

Setup Code

The setup code for HomeKit must be an 8-digit number. For instance, 10148005. When generating the accessory SRP verifier, format the setup code as XXX-XX-XXX. So, 10148005 becomes 101-48-005.

Setup ID

Each accessory requires a unique 4-character alphanumeric setup ID. This ID persists across reboots and resets. Ensure it differs from the DeviceID, serial number, model, or accessory name. Here’s an example configuration:

homekit_server_config_t config = { 
.accessories = accessories,
.password = "123-45-678",
.setupId = "1QJ8",
};

QR Code Prerequisites

To generate the QR code, you need Python and a few libraries. If you’re on macOS, start by installing Homebrew, the missing package manager:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Add Homebrew to your PATH:

export PATH="/usr/local/opt/python/libexec/bin:$PATH"

For macOS 10.12 (Sierra) or older, use:

export PATH=/usr/local/bin:/usr/local/sbin:$PATH

Install Python 3:

brew install python

Next, install the necessary Python libraries:

python3 -m pip install --upgrade pip 
python3 -m pip install --upgrade Pillow
python3 -m pip install qrcode

Generate the QR Code

With the prerequisites installed, you can now generate the QR code using the provided script. The command structure is:

tools/gen_qrcode <category> <setup code> <setup ID> <output file>

For example:

tools/gen_qrcode 5 123-45-678 1QJ8 qrcode.png

Breakdown

  • 5: HomeKit accessory category (in this case, lighting).
  • 123-45-678: The formatted setup code.
  • 1QJ8: The setup ID.
  • qrcode.png: The output file where the QR code will be saved.

Press enter, and the QR code will be generated and saved as qrcode.png in the tools folder.

HomeKit Accessory Categories

Here’s a handy table for HomeKit accessory categories:

CategoryNumber
Other1
Bridges2
Fans3
Garage door openers4
Lighting5
Locks6
Outlets7
Switches8
Thermostats9
Sensors10
Security systems11
Doors12
Windows13
Window coverings14
Programmable switches15
Range extenders16
IP cameras17
Video doorbells18
Air purifiers19
Heaters20
Air conditioners21
Humidifiers22
Dehumidifiers23
Apple TV24
Speakers26
Airport27
Sprinklers28
Faucets29
Shower heads30
Televisions31
Target remotes32

By following these steps, you’ll have a QR code ready for pairing your ESP32 HomeKit accessory with ease. Happy hacking!

Scroll to Top