Arduino With ESP32 and Native Apple HomeKit Integration
by YuriK1972 in Circuits > Arduino
2344 Views, 5 Favorites, 0 Comments
Arduino With ESP32 and Native Apple HomeKit Integration
This Instructable will give you a quick and easy way to handle an ESP32 board from Apple's HomeKit on an iOS device.
This is very simple integration without any additional Raspberry , MQTT ,.....
You just need only ESP32 board and iOS device !
Most of the people like uses Arduino IDE, this is simplify a process, therefore main subject of this publication is Arduino library for ESP32
Setup Library for Arduino IDE
- You need to prepare Arduino IDE working with ESP32 platform
This out of scope of this explanation, detail instruction can be found like here
In my case I have used
- Arduino IDE 1.8.10
- esp32 package for Arduino ver 1.0.4
2. Then download and install ESPHap Library. You can simple download and copy content into your Arduino libraries folder. Usually (Windows OS) it's C:\Users\\Arduino\Libraries
3. Finally you need to install and prepare wolfssl library, check readme how to do that. This library should be as well under Arduino libraries folder. The simplest way to install wolfssl is restoring content of archive wolfssl.rar from the ESPHap library under wolfssl folder to ...Arduino\Libraries\wolfssl
Create Your Arduino Sketch
1. Go to examples directory of esphap library and open sketch EspHapLed.ino
2. Make changes to connect to your WiFi on the following lines
const char* ssid = "your ssid";
const char* password = "pwd to ssid";
3. Compile skecth and upload to the ESP 32 board
4. Additionally you can change following constants
const int identity_led=2;
const int led_gpio = 4;
identity_led is responsible for gpio of led whicl will blink on the identification (feathure of Apple Home Kit)
led_gpio gpio of your led which will be turned On/Off from Apple
Connect to Apple Home Kit
When sketch is started on ESP32 you should see something like on the picture above.
Than open Home Kit App on your iOS device , and select or create new Home
1. Press Add (+)
2. Select Add accessory.
3. Press I don't have a Code or Cannot scan (further on scanning will be added)
4. if everything going fine you should see your new esp device in a list (see picture)
5. Select device and confirm adding without official certification
6. Type password 11111111
7. That All ! You should see that device paired succesfully, otherwise start pairing process again..
Enjoy
Now you can manage your ESP32 from your Apple device, including all Apple Home Kit features:
- Siri
- Apple Home Kit automation scenarious
As soon as first pairing is happened, the ESP32 is not more visible for the next pairing. The pairing data on the given sketch are stored under SPIFFS file system within \pair.dat file. This is allows to simple manage/keep pairings.
For instance you can backup this file and restore after to keep existing pairing. By removing this file the device will be ready for new pairing.
More Complex Scenarious
At this moment only one examples of simple sketh for Turning On/Off led is provided.
This is applicable not only for led, but for any modules which supports two states: On/Off, for instance Relay module
Hovewer library is not limited only for that.
The background implementation allows to do much more with any available accesories on the Apple Home Kit
1. RGB light
2. Dimmable
3. Temperature and humidity sensors
more and more
For instance see examples of usage here. This is ESP-IDF implemetation but the same code
Welcome with any additional sketch examples